@fragments-sdk/cli 0.2.2

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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +4783 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/chunk-4FDQSGKX.js +786 -0
  7. package/dist/chunk-4FDQSGKX.js.map +1 -0
  8. package/dist/chunk-7H2MMGYG.js +369 -0
  9. package/dist/chunk-7H2MMGYG.js.map +1 -0
  10. package/dist/chunk-BSCG3IP7.js +619 -0
  11. package/dist/chunk-BSCG3IP7.js.map +1 -0
  12. package/dist/chunk-LY2CFFPY.js +898 -0
  13. package/dist/chunk-LY2CFFPY.js.map +1 -0
  14. package/dist/chunk-MUZ6CM66.js +6636 -0
  15. package/dist/chunk-MUZ6CM66.js.map +1 -0
  16. package/dist/chunk-OAENNG3G.js +1489 -0
  17. package/dist/chunk-OAENNG3G.js.map +1 -0
  18. package/dist/chunk-XHNKNI6J.js +235 -0
  19. package/dist/chunk-XHNKNI6J.js.map +1 -0
  20. package/dist/core-DWKLGY4N.js +68 -0
  21. package/dist/core-DWKLGY4N.js.map +1 -0
  22. package/dist/generate-4LQNJ7SX.js +249 -0
  23. package/dist/generate-4LQNJ7SX.js.map +1 -0
  24. package/dist/index.d.ts +775 -0
  25. package/dist/index.js +41 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/init-EMVI47QG.js +416 -0
  28. package/dist/init-EMVI47QG.js.map +1 -0
  29. package/dist/mcp-bin.d.ts +1 -0
  30. package/dist/mcp-bin.js +1117 -0
  31. package/dist/mcp-bin.js.map +1 -0
  32. package/dist/scan-4YPRF7FV.js +12 -0
  33. package/dist/scan-4YPRF7FV.js.map +1 -0
  34. package/dist/service-QSZMZJBJ.js +208 -0
  35. package/dist/service-QSZMZJBJ.js.map +1 -0
  36. package/dist/static-viewer-MIPGZ4Z7.js +12 -0
  37. package/dist/static-viewer-MIPGZ4Z7.js.map +1 -0
  38. package/dist/test-SQ5ZHXWU.js +1067 -0
  39. package/dist/test-SQ5ZHXWU.js.map +1 -0
  40. package/dist/tokens-HSGMYK64.js +173 -0
  41. package/dist/tokens-HSGMYK64.js.map +1 -0
  42. package/dist/viewer-YRF4SQE4.js +11101 -0
  43. package/dist/viewer-YRF4SQE4.js.map +1 -0
  44. package/package.json +107 -0
  45. package/src/ai.ts +266 -0
  46. package/src/analyze.ts +265 -0
  47. package/src/bin.ts +916 -0
  48. package/src/build.ts +248 -0
  49. package/src/commands/a11y.ts +302 -0
  50. package/src/commands/add.ts +313 -0
  51. package/src/commands/audit.ts +195 -0
  52. package/src/commands/baseline.ts +221 -0
  53. package/src/commands/build.ts +144 -0
  54. package/src/commands/compare.ts +337 -0
  55. package/src/commands/context.ts +107 -0
  56. package/src/commands/dev.ts +107 -0
  57. package/src/commands/enhance.ts +858 -0
  58. package/src/commands/generate.ts +391 -0
  59. package/src/commands/init.ts +531 -0
  60. package/src/commands/link/figma.ts +645 -0
  61. package/src/commands/link/index.ts +10 -0
  62. package/src/commands/link/storybook.ts +267 -0
  63. package/src/commands/list.ts +49 -0
  64. package/src/commands/metrics.ts +114 -0
  65. package/src/commands/reset.ts +242 -0
  66. package/src/commands/scan.ts +537 -0
  67. package/src/commands/storygen.ts +207 -0
  68. package/src/commands/tokens.ts +251 -0
  69. package/src/commands/validate.ts +93 -0
  70. package/src/commands/verify.ts +215 -0
  71. package/src/core/composition.test.ts +262 -0
  72. package/src/core/composition.ts +255 -0
  73. package/src/core/config.ts +84 -0
  74. package/src/core/constants.ts +111 -0
  75. package/src/core/context.ts +380 -0
  76. package/src/core/defineSegment.ts +137 -0
  77. package/src/core/discovery.ts +337 -0
  78. package/src/core/figma.ts +263 -0
  79. package/src/core/fragment-types.ts +214 -0
  80. package/src/core/generators/context.ts +389 -0
  81. package/src/core/generators/index.ts +23 -0
  82. package/src/core/generators/registry.ts +364 -0
  83. package/src/core/generators/typescript-extractor.ts +374 -0
  84. package/src/core/importAnalyzer.ts +217 -0
  85. package/src/core/index.ts +149 -0
  86. package/src/core/loader.ts +155 -0
  87. package/src/core/node.ts +63 -0
  88. package/src/core/parser.ts +551 -0
  89. package/src/core/previewLoader.ts +172 -0
  90. package/src/core/schema/fragment.schema.json +189 -0
  91. package/src/core/schema/registry.schema.json +137 -0
  92. package/src/core/schema.ts +182 -0
  93. package/src/core/storyAdapter.test.ts +571 -0
  94. package/src/core/storyAdapter.ts +761 -0
  95. package/src/core/token-types.ts +287 -0
  96. package/src/core/types.ts +754 -0
  97. package/src/diff.ts +323 -0
  98. package/src/index.ts +43 -0
  99. package/src/mcp/__tests__/projectFields.test.ts +130 -0
  100. package/src/mcp/bin.ts +36 -0
  101. package/src/mcp/index.ts +8 -0
  102. package/src/mcp/server.ts +1310 -0
  103. package/src/mcp/utils.ts +54 -0
  104. package/src/mcp-bin.ts +36 -0
  105. package/src/migrate/__tests__/argTypes/argTypes.test.ts +189 -0
  106. package/src/migrate/__tests__/args/args.test.ts +452 -0
  107. package/src/migrate/__tests__/meta/meta.test.ts +198 -0
  108. package/src/migrate/__tests__/stories/stories.test.ts +278 -0
  109. package/src/migrate/__tests__/utils/utils.test.ts +371 -0
  110. package/src/migrate/__tests__/values/values.test.ts +303 -0
  111. package/src/migrate/bin.ts +108 -0
  112. package/src/migrate/converter.ts +658 -0
  113. package/src/migrate/detect.ts +196 -0
  114. package/src/migrate/index.ts +45 -0
  115. package/src/migrate/migrate.ts +163 -0
  116. package/src/migrate/parser.ts +1136 -0
  117. package/src/migrate/report.ts +624 -0
  118. package/src/migrate/types.ts +169 -0
  119. package/src/screenshot.ts +249 -0
  120. package/src/service/__tests__/ast-utils.test.ts +426 -0
  121. package/src/service/__tests__/enhance-scanner.test.ts +200 -0
  122. package/src/service/__tests__/figma/figma.test.ts +652 -0
  123. package/src/service/__tests__/metrics-store.test.ts +409 -0
  124. package/src/service/__tests__/patch-generator.test.ts +186 -0
  125. package/src/service/__tests__/props-extractor.test.ts +365 -0
  126. package/src/service/__tests__/token-registry.test.ts +267 -0
  127. package/src/service/analytics.ts +659 -0
  128. package/src/service/ast-utils.ts +444 -0
  129. package/src/service/browser-pool.ts +339 -0
  130. package/src/service/capture.ts +267 -0
  131. package/src/service/diff.ts +279 -0
  132. package/src/service/enhance/aggregator.ts +489 -0
  133. package/src/service/enhance/cache.ts +275 -0
  134. package/src/service/enhance/codebase-scanner.ts +357 -0
  135. package/src/service/enhance/context-generator.ts +529 -0
  136. package/src/service/enhance/doc-extractor.ts +523 -0
  137. package/src/service/enhance/index.ts +131 -0
  138. package/src/service/enhance/props-extractor.ts +665 -0
  139. package/src/service/enhance/scanner.ts +445 -0
  140. package/src/service/enhance/storybook-parser.ts +552 -0
  141. package/src/service/enhance/types.ts +346 -0
  142. package/src/service/enhance/variant-renderer.ts +479 -0
  143. package/src/service/figma.ts +1008 -0
  144. package/src/service/index.ts +249 -0
  145. package/src/service/metrics-store.ts +333 -0
  146. package/src/service/patch-generator.ts +349 -0
  147. package/src/service/report.ts +854 -0
  148. package/src/service/storage.ts +401 -0
  149. package/src/service/token-fixes.ts +281 -0
  150. package/src/service/token-parser.ts +504 -0
  151. package/src/service/token-registry.ts +721 -0
  152. package/src/service/utils.ts +172 -0
  153. package/src/setup.ts +241 -0
  154. package/src/shared/command-wrapper.ts +81 -0
  155. package/src/shared/dev-server-client.ts +199 -0
  156. package/src/shared/index.ts +8 -0
  157. package/src/shared/segment-loader.ts +59 -0
  158. package/src/shared/types.ts +147 -0
  159. package/src/static-viewer.ts +715 -0
  160. package/src/test/discovery.ts +172 -0
  161. package/src/test/index.ts +281 -0
  162. package/src/test/reporters/console.ts +194 -0
  163. package/src/test/reporters/json.ts +190 -0
  164. package/src/test/reporters/junit.ts +186 -0
  165. package/src/test/runner.ts +598 -0
  166. package/src/test/types.ts +245 -0
  167. package/src/test/watch.ts +200 -0
  168. package/src/validators.ts +152 -0
  169. package/src/viewer/__tests__/jsx-parser.test.ts +502 -0
  170. package/src/viewer/__tests__/render-utils.test.ts +232 -0
  171. package/src/viewer/__tests__/style-utils.test.ts +404 -0
  172. package/src/viewer/bin.ts +86 -0
  173. package/src/viewer/cli/health.ts +256 -0
  174. package/src/viewer/cli/index.ts +33 -0
  175. package/src/viewer/cli/scan.ts +124 -0
  176. package/src/viewer/cli/utils.ts +174 -0
  177. package/src/viewer/components/AccessibilityPanel.tsx +1404 -0
  178. package/src/viewer/components/ActionCapture.tsx +172 -0
  179. package/src/viewer/components/ActionsPanel.tsx +371 -0
  180. package/src/viewer/components/App.tsx +638 -0
  181. package/src/viewer/components/BottomPanel.tsx +224 -0
  182. package/src/viewer/components/CodePanel.tsx +589 -0
  183. package/src/viewer/components/CommandPalette.tsx +336 -0
  184. package/src/viewer/components/ComponentGraph.tsx +394 -0
  185. package/src/viewer/components/ComponentHeader.tsx +85 -0
  186. package/src/viewer/components/ContractPanel.tsx +234 -0
  187. package/src/viewer/components/ErrorBoundary.tsx +85 -0
  188. package/src/viewer/components/FigmaEmbed.tsx +231 -0
  189. package/src/viewer/components/FragmentEditor.tsx +485 -0
  190. package/src/viewer/components/HealthDashboard.tsx +452 -0
  191. package/src/viewer/components/HmrStatusIndicator.tsx +71 -0
  192. package/src/viewer/components/Icons.tsx +417 -0
  193. package/src/viewer/components/InteractionsPanel.tsx +720 -0
  194. package/src/viewer/components/IsolatedPreviewFrame.tsx +321 -0
  195. package/src/viewer/components/IsolatedRender.tsx +111 -0
  196. package/src/viewer/components/KeyboardShortcutsHelp.tsx +89 -0
  197. package/src/viewer/components/LandingPage.tsx +441 -0
  198. package/src/viewer/components/Layout.tsx +22 -0
  199. package/src/viewer/components/LeftSidebar.tsx +391 -0
  200. package/src/viewer/components/MultiViewportPreview.tsx +429 -0
  201. package/src/viewer/components/PreviewArea.tsx +404 -0
  202. package/src/viewer/components/PreviewFrameHost.tsx +310 -0
  203. package/src/viewer/components/PreviewPane.tsx +150 -0
  204. package/src/viewer/components/PreviewToolbar.tsx +176 -0
  205. package/src/viewer/components/PropsEditor.tsx +512 -0
  206. package/src/viewer/components/PropsTable.tsx +98 -0
  207. package/src/viewer/components/RelationsSection.tsx +57 -0
  208. package/src/viewer/components/ResizablePanel.tsx +328 -0
  209. package/src/viewer/components/RightSidebar.tsx +118 -0
  210. package/src/viewer/components/ScreenshotButton.tsx +90 -0
  211. package/src/viewer/components/Sidebar.tsx +169 -0
  212. package/src/viewer/components/SkeletonLoader.tsx +156 -0
  213. package/src/viewer/components/StoryRenderer.tsx +128 -0
  214. package/src/viewer/components/ThemeProvider.tsx +96 -0
  215. package/src/viewer/components/Toast.tsx +67 -0
  216. package/src/viewer/components/TokenStylePanel.tsx +708 -0
  217. package/src/viewer/components/UsageSection.tsx +95 -0
  218. package/src/viewer/components/VariantMatrix.tsx +350 -0
  219. package/src/viewer/components/VariantRenderer.tsx +131 -0
  220. package/src/viewer/components/VariantTabs.tsx +84 -0
  221. package/src/viewer/components/ViewportSelector.tsx +165 -0
  222. package/src/viewer/components/_future/CreatePage.tsx +836 -0
  223. package/src/viewer/composition-renderer.ts +381 -0
  224. package/src/viewer/constants/index.ts +1 -0
  225. package/src/viewer/constants/ui.ts +185 -0
  226. package/src/viewer/entry.tsx +299 -0
  227. package/src/viewer/hooks/index.ts +2 -0
  228. package/src/viewer/hooks/useA11yCache.ts +383 -0
  229. package/src/viewer/hooks/useA11yService.ts +498 -0
  230. package/src/viewer/hooks/useActions.ts +138 -0
  231. package/src/viewer/hooks/useAppState.ts +124 -0
  232. package/src/viewer/hooks/useFigmaIntegration.ts +132 -0
  233. package/src/viewer/hooks/useHmrStatus.ts +109 -0
  234. package/src/viewer/hooks/useKeyboardShortcuts.ts +222 -0
  235. package/src/viewer/hooks/usePreviewBridge.ts +347 -0
  236. package/src/viewer/hooks/useScrollSpy.ts +78 -0
  237. package/src/viewer/hooks/useUrlState.ts +330 -0
  238. package/src/viewer/hooks/useViewSettings.ts +125 -0
  239. package/src/viewer/index.html +28 -0
  240. package/src/viewer/index.ts +14 -0
  241. package/src/viewer/intelligence/healthReport.ts +505 -0
  242. package/src/viewer/intelligence/styleDrift.ts +340 -0
  243. package/src/viewer/intelligence/usageScanner.ts +309 -0
  244. package/src/viewer/jsx-parser.ts +485 -0
  245. package/src/viewer/postcss.config.js +6 -0
  246. package/src/viewer/preview-frame-entry.tsx +25 -0
  247. package/src/viewer/preview-frame.html +109 -0
  248. package/src/viewer/render-template.html +68 -0
  249. package/src/viewer/render-utils.ts +170 -0
  250. package/src/viewer/server.ts +276 -0
  251. package/src/viewer/style-utils.ts +414 -0
  252. package/src/viewer/styles/globals.css +355 -0
  253. package/src/viewer/tailwind.config.js +37 -0
  254. package/src/viewer/types/a11y.ts +197 -0
  255. package/src/viewer/utils/a11y-fixes.ts +471 -0
  256. package/src/viewer/utils/actionExport.ts +372 -0
  257. package/src/viewer/utils/colorSchemes.ts +201 -0
  258. package/src/viewer/utils/detectRelationships.ts +256 -0
  259. package/src/viewer/vite-plugin.ts +2143 -0
@@ -0,0 +1,754 @@
1
+ import type { ComponentType, ReactNode, JSX } from "react";
2
+
3
+ /**
4
+ * A React component that can be used in a segment definition.
5
+ * This type is intentionally broad to support various React component patterns
6
+ * including FC, forwardRef, memo, and class components across different React versions.
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ export type SegmentComponent<TProps = any> =
10
+ | ComponentType<TProps>
11
+ | ((props: TProps) => ReactNode | JSX.Element | null);
12
+
13
+ /**
14
+ * Metadata about the component
15
+ */
16
+ export interface SegmentMeta {
17
+ /** Component display name */
18
+ name: string;
19
+
20
+ /** Brief description of the component's purpose */
21
+ description: string;
22
+
23
+ /** Category for organizing components (e.g., "actions", "forms", "layout") */
24
+ category: string;
25
+
26
+ /** Optional tags for additional categorization */
27
+ tags?: string[];
28
+
29
+ /** Component status */
30
+ status?: "stable" | "beta" | "deprecated" | "experimental";
31
+
32
+ /** Version when component was introduced */
33
+ since?: string;
34
+
35
+ /** Figma frame URL for design verification */
36
+ figma?: string;
37
+
38
+ /** Figma property mappings (how Figma props map to code props) */
39
+ figmaProps?: Record<string, FigmaPropMapping>;
40
+ }
41
+
42
+ /**
43
+ * Figma property mapping types - describes how a Figma property maps to code
44
+ */
45
+ export type FigmaPropMapping =
46
+ | FigmaStringMapping
47
+ | FigmaBooleanMapping
48
+ | FigmaEnumMapping
49
+ | FigmaInstanceMapping
50
+ | FigmaChildrenMapping
51
+ | FigmaTextContentMapping;
52
+
53
+ /** Maps a Figma text property to a string prop */
54
+ export interface FigmaStringMapping {
55
+ __type: 'figma-string';
56
+ figmaProperty: string;
57
+ }
58
+
59
+ /** Maps a Figma boolean property to a boolean prop (with optional value mapping) */
60
+ export interface FigmaBooleanMapping {
61
+ __type: 'figma-boolean';
62
+ figmaProperty: string;
63
+ valueMapping?: { true: unknown; false: unknown };
64
+ }
65
+
66
+ /** Maps a Figma variant property to an enum prop */
67
+ export interface FigmaEnumMapping {
68
+ __type: 'figma-enum';
69
+ figmaProperty: string;
70
+ valueMapping: Record<string, unknown>;
71
+ }
72
+
73
+ /** References a nested Figma component instance */
74
+ export interface FigmaInstanceMapping {
75
+ __type: 'figma-instance';
76
+ figmaProperty: string;
77
+ }
78
+
79
+ /** Renders children from Figma layer names */
80
+ export interface FigmaChildrenMapping {
81
+ __type: 'figma-children';
82
+ layers: string[];
83
+ }
84
+
85
+ /** Extracts text content from a Figma text layer */
86
+ export interface FigmaTextContentMapping {
87
+ __type: 'figma-text-content';
88
+ layer: string;
89
+ }
90
+
91
+ /**
92
+ * Usage guidelines for AI agents and developers
93
+ */
94
+ export interface SegmentUsage {
95
+ /** When to use this component */
96
+ when: string[];
97
+
98
+ /** When NOT to use this component (with alternatives) */
99
+ whenNot: string[];
100
+
101
+ /** Additional usage guidelines and best practices */
102
+ guidelines?: string[];
103
+
104
+ /** Accessibility considerations */
105
+ accessibility?: string[];
106
+ }
107
+
108
+ /**
109
+ * Prop type definitions
110
+ */
111
+ export type PropType =
112
+ | { type: "string"; pattern?: string }
113
+ | { type: "number"; min?: number; max?: number }
114
+ | { type: "boolean" }
115
+ | { type: "enum"; values: readonly string[] }
116
+ | { type: "function"; signature?: string }
117
+ | { type: "node" }
118
+ | { type: "element" }
119
+ | { type: "object"; shape?: Record<string, PropDefinition> }
120
+ | { type: "array"; items?: PropType }
121
+ | { type: "union"; types: PropType[] }
122
+ | { type: "custom"; typescript: string };
123
+
124
+ /**
125
+ * Storybook control types for UI rendering
126
+ */
127
+ export type ControlType =
128
+ | "text"
129
+ | "number"
130
+ | "range"
131
+ | "boolean"
132
+ | "select"
133
+ | "multi-select"
134
+ | "radio"
135
+ | "inline-radio"
136
+ | "check"
137
+ | "inline-check"
138
+ | "object"
139
+ | "file"
140
+ | "color"
141
+ | "date";
142
+
143
+ /**
144
+ * Definition for a single prop
145
+ */
146
+ export interface PropDefinition {
147
+ /** The prop type */
148
+ type: PropType["type"];
149
+
150
+ /** For enum types, the allowed values */
151
+ values?: readonly string[];
152
+
153
+ /** Default value if not provided */
154
+ default?: unknown;
155
+
156
+ /** Description of what this prop does */
157
+ description: string;
158
+
159
+ /** Whether this prop is required */
160
+ required?: boolean;
161
+
162
+ /** Usage constraints for AI agents */
163
+ constraints?: string[];
164
+
165
+ /** Additional type details for complex types */
166
+ typeDetails?: Omit<PropType, "type">;
167
+
168
+ /** Original Storybook control type for UI rendering (e.g., "color", "date", "range") */
169
+ controlType?: ControlType;
170
+
171
+ /** Control options (e.g., min/max for range, presetColors for color) */
172
+ controlOptions?: {
173
+ min?: number;
174
+ max?: number;
175
+ step?: number;
176
+ presetColors?: string[];
177
+ };
178
+ }
179
+
180
+ /**
181
+ * Relationship types between components
182
+ */
183
+ export type RelationshipType =
184
+ | "alternative" // Use instead of this component in certain cases
185
+ | "sibling" // Related component at same level
186
+ | "parent" // This component should be wrapped by
187
+ | "child" // This component should contain
188
+ | "composition"; // Used together as compound component
189
+
190
+ /**
191
+ * Relationship to another component
192
+ */
193
+ export interface ComponentRelation {
194
+ /** Name of the related component */
195
+ component: string;
196
+
197
+ /** Type of relationship */
198
+ relationship: RelationshipType;
199
+
200
+ /** Explanation of the relationship */
201
+ note: string;
202
+ }
203
+
204
+ /**
205
+ * Loader function type for async data loading before render
206
+ */
207
+ export type VariantLoader = () => Promise<Record<string, unknown>>;
208
+
209
+ /**
210
+ * Play function context passed during interaction testing
211
+ */
212
+ export interface PlayFunctionContext {
213
+ /** The rendered canvas element containing the story */
214
+ canvasElement: HTMLElement;
215
+ /** Args passed to the story */
216
+ args: Record<string, unknown>;
217
+ /** Step function for organizing interactions */
218
+ step: (name: string, fn: () => Promise<void>) => Promise<void>;
219
+ }
220
+
221
+ /**
222
+ * Play function type for interaction testing
223
+ */
224
+ export type PlayFunction = (context: PlayFunctionContext) => Promise<void>;
225
+
226
+ /**
227
+ * Options passed to variant render function
228
+ */
229
+ export interface VariantRenderOptions {
230
+ /** Props/args to override the variant defaults */
231
+ args?: Record<string, unknown>;
232
+ /** Data loaded from async loaders */
233
+ loadedData?: Record<string, unknown>;
234
+ }
235
+
236
+ /**
237
+ * A single variant/example of the component
238
+ */
239
+ export interface SegmentVariant {
240
+ /** Variant name */
241
+ name: string;
242
+
243
+ /** Description of when to use this variant */
244
+ description: string;
245
+
246
+ /** Render function that returns the component example
247
+ * @param options - Optional args overrides and loaded data
248
+ */
249
+ render: (options?: VariantRenderOptions) => ReactNode;
250
+
251
+ /** Optional code string for display (auto-generated if not provided) */
252
+ code?: string;
253
+
254
+ /** Figma frame URL for this specific variant (overrides meta.figma) */
255
+ figma?: string;
256
+
257
+ /** Whether this variant has a Storybook play function (for display purposes) */
258
+ hasPlayFunction?: boolean;
259
+
260
+ /** The actual play function for interaction testing */
261
+ play?: PlayFunction;
262
+
263
+ /** Storybook story ID for this variant (generated by @storybook/csf toId) */
264
+ storyId?: string;
265
+
266
+ /** Optional tags for this variant (inherited from story tags) */
267
+ tags?: string[];
268
+
269
+ /** Async loaders to execute before rendering (from Storybook loaders) */
270
+ loaders?: VariantLoader[];
271
+
272
+ /** The args/props used to render this variant (for code generation) */
273
+ args?: Record<string, unknown>;
274
+ }
275
+
276
+ /**
277
+ * Agent-optimized contract metadata
278
+ * Provides compact, structured data for AI code generation
279
+ */
280
+ export interface SegmentContract {
281
+ /** Short prop descriptions for agents (e.g., "variant: primary|secondary (required)") */
282
+ propsSummary?: string[];
283
+
284
+ /** Accessibility rule IDs for lookup in glossary (e.g., "A11Y_BTN_LABEL") */
285
+ a11yRules?: string[];
286
+
287
+ /** Banned patterns in codebase - triggers warnings during code review */
288
+ bans?: Array<{
289
+ /** Pattern to match (regex string or literal) */
290
+ pattern: string;
291
+ /** Message explaining why this pattern is banned and what to use instead */
292
+ message: string;
293
+ }>;
294
+
295
+ /** Scenario tags for use-case matching (e.g., "form.submit", "navigation.primary") */
296
+ scenarioTags?: string[];
297
+ }
298
+
299
+ /**
300
+ * Provenance tracking for generated segments
301
+ * Helps distinguish human-authored from machine-generated content
302
+ */
303
+ export interface SegmentGenerated {
304
+ /** Source of this segment definition */
305
+ source: "storybook" | "manual" | "ai";
306
+
307
+ /** Original source file (e.g., "Button.stories.tsx") */
308
+ sourceFile?: string;
309
+
310
+ /** Confidence score from 0-1 (how reliable the extraction was) */
311
+ confidence?: number;
312
+
313
+ /** ISO timestamp when this was generated */
314
+ timestamp?: string;
315
+ }
316
+
317
+ /**
318
+ * Complete segment definition
319
+ */
320
+ export interface SegmentDefinition<TProps = unknown> {
321
+ /** The component being documented */
322
+ component: SegmentComponent<TProps>;
323
+
324
+ /** Component metadata */
325
+ meta: SegmentMeta;
326
+
327
+ /** Usage guidelines */
328
+ usage: SegmentUsage;
329
+
330
+ /** Props documentation */
331
+ props: Record<string, PropDefinition>;
332
+
333
+ /** Relationships to other components */
334
+ relations?: ComponentRelation[];
335
+
336
+ /** Component variants/examples */
337
+ variants: SegmentVariant[];
338
+
339
+ /** Agent-optimized contract metadata */
340
+ contract?: SegmentContract;
341
+
342
+ /** Provenance tracking (for generated segments) */
343
+ _generated?: SegmentGenerated;
344
+ }
345
+
346
+ /**
347
+ * Registry generation options
348
+ */
349
+ export interface RegistryOptions {
350
+ /** Only include components that have a corresponding .stories.tsx file */
351
+ requireStory?: boolean;
352
+
353
+ /** Only include components that are exported (public API) */
354
+ publicOnly?: boolean;
355
+
356
+ /** Maximum depth for category inference from directory structure (default: 1) */
357
+ categoryDepth?: number;
358
+
359
+ /** Include props in registry (default: false - AI can read TypeScript directly) */
360
+ includeProps?: boolean;
361
+
362
+ /** Include full fragment data in registry (default: false - reference fragmentPath instead) */
363
+ embedFragments?: boolean;
364
+ }
365
+
366
+ /**
367
+ * Design token configuration
368
+ */
369
+ export interface TokenConfig {
370
+ /**
371
+ * Glob patterns for files to scan for tokens
372
+ * e.g., ["src/styles/theme.scss", "src/styles/variables.css"]
373
+ */
374
+ include: string[];
375
+
376
+ /**
377
+ * Glob patterns to exclude
378
+ * @example ["node_modules"]
379
+ */
380
+ exclude?: string[];
381
+
382
+ /**
383
+ * Map CSS selectors to theme names
384
+ * @example { ":root": "default", "[data-theme='dark']": "dark" }
385
+ */
386
+ themeSelectors?: Record<string, string>;
387
+
388
+ /** Enable token comparison in style diffs (default: true) */
389
+ enabled?: boolean;
390
+ }
391
+
392
+ /**
393
+ * CI configuration for automated compliance checks
394
+ */
395
+ export interface CIConfig {
396
+ /** Minimum compliance percentage to pass (default: 80) */
397
+ minCompliance?: number;
398
+
399
+ /** Whether to fail on any visual regression */
400
+ failOnDiff?: boolean;
401
+
402
+ /** Whether to output JSON format */
403
+ jsonOutput?: boolean;
404
+ }
405
+
406
+ /**
407
+ * Config file structure
408
+ */
409
+ export interface FragmentsConfig {
410
+ /** Glob patterns for finding segment/fragment files */
411
+ include: string[];
412
+
413
+ /** Glob patterns to exclude */
414
+ exclude?: string[];
415
+
416
+ /** Glob patterns for finding component files (for coverage validation) */
417
+ components?: string[];
418
+
419
+ /** Output path for compiled output */
420
+ outFile?: string;
421
+
422
+ /** Framework adapter to use */
423
+ framework?: "react" | "vue" | "svelte";
424
+
425
+ /** Figma file URL for the design system (used by `fragments link`) */
426
+ figmaFile?: string;
427
+
428
+ /** Figma access token (alternative to FIGMA_ACCESS_TOKEN env var) */
429
+ figmaToken?: string;
430
+
431
+ /** Screenshot configuration */
432
+ screenshots?: ScreenshotConfig;
433
+
434
+ /** Service configuration */
435
+ service?: ServiceConfig;
436
+
437
+ /** Registry generation options */
438
+ registry?: RegistryOptions;
439
+
440
+ /** Design token discovery and mapping configuration */
441
+ tokens?: TokenConfig;
442
+
443
+ /** CI pipeline configuration */
444
+ ci?: CIConfig;
445
+ }
446
+
447
+ /**
448
+ * @deprecated Use FragmentsConfig instead
449
+ */
450
+ export type SegmentsConfig = FragmentsConfig;
451
+
452
+ /**
453
+ * Screenshot capture configuration
454
+ */
455
+ export interface ScreenshotConfig {
456
+ /** Default viewport for captures */
457
+ viewport?: Viewport;
458
+
459
+ /** Diff threshold percentage (0-100) */
460
+ threshold?: number;
461
+
462
+ /** Additional delay after render before capture (ms) */
463
+ delay?: number;
464
+
465
+ /** Output directory for baselines (relative to project root) */
466
+ outputDir?: string;
467
+
468
+ /** Themes to capture */
469
+ themes?: Theme[];
470
+ }
471
+
472
+ /**
473
+ * Service configuration
474
+ */
475
+ export interface ServiceConfig {
476
+ /** Browser pool size */
477
+ poolSize?: number;
478
+
479
+ /** Idle timeout before shutdown (ms) */
480
+ idleTimeout?: number;
481
+ }
482
+
483
+ /**
484
+ * Viewport dimensions
485
+ */
486
+ export interface Viewport {
487
+ width: number;
488
+ height: number;
489
+ deviceScaleFactor?: number;
490
+ }
491
+
492
+ /**
493
+ * Theme identifier
494
+ */
495
+ export type Theme = "light" | "dark";
496
+
497
+ /**
498
+ * Screenshot metadata
499
+ */
500
+ export interface Screenshot {
501
+ /** PNG image data */
502
+ data: Buffer;
503
+
504
+ /** SHA-256 hash of image data (for change detection) */
505
+ hash: string;
506
+
507
+ /** Viewport used for capture */
508
+ viewport: Viewport;
509
+
510
+ /** When this screenshot was taken */
511
+ capturedAt: Date;
512
+
513
+ /** Capture metadata */
514
+ metadata: ScreenshotMetadata;
515
+ }
516
+
517
+ /**
518
+ * Screenshot metadata
519
+ */
520
+ export interface ScreenshotMetadata {
521
+ /** Component name */
522
+ component: string;
523
+
524
+ /** Variant name */
525
+ variant: string;
526
+
527
+ /** Theme used */
528
+ theme: Theme;
529
+
530
+ /** Time to render the component (ms) */
531
+ renderTimeMs: number;
532
+
533
+ /** Time to capture the screenshot (ms) */
534
+ captureTimeMs: number;
535
+ }
536
+
537
+ /**
538
+ * Result of comparing two screenshots
539
+ */
540
+ export interface DiffResult {
541
+ /** Whether images are considered matching (below threshold) */
542
+ matches: boolean;
543
+
544
+ /** Percentage of pixels that differ (0-100) */
545
+ diffPercentage: number;
546
+
547
+ /** Number of differing pixels */
548
+ diffPixelCount: number;
549
+
550
+ /** Total pixels compared */
551
+ totalPixels: number;
552
+
553
+ /** PNG image highlighting differences */
554
+ diffImage?: Buffer;
555
+
556
+ /** Bounding boxes of changed regions */
557
+ changedRegions: BoundingBox[];
558
+
559
+ /** Time taken to compute diff (ms) */
560
+ diffTimeMs: number;
561
+ }
562
+
563
+ /**
564
+ * Bounding box for changed region
565
+ */
566
+ export interface BoundingBox {
567
+ x: number;
568
+ y: number;
569
+ width: number;
570
+ height: number;
571
+ }
572
+
573
+ /**
574
+ * Baseline information stored in manifest
575
+ */
576
+ export interface BaselineInfo {
577
+ /** Component name */
578
+ component: string;
579
+
580
+ /** Variant name */
581
+ variant: string;
582
+
583
+ /** Theme */
584
+ theme: Theme;
585
+
586
+ /** Relative path to image file */
587
+ path: string;
588
+
589
+ /** SHA-256 hash */
590
+ hash: string;
591
+
592
+ /** Viewport used */
593
+ viewport: Viewport;
594
+
595
+ /** When captured */
596
+ capturedAt: string;
597
+
598
+ /** File size in bytes */
599
+ fileSize: number;
600
+ }
601
+
602
+ /**
603
+ * Manifest file structure
604
+ */
605
+ export interface Manifest {
606
+ /** Schema version */
607
+ version: "1.0.0";
608
+
609
+ /** When manifest was generated */
610
+ generatedAt: string;
611
+
612
+ /** Configuration used for capture */
613
+ config: {
614
+ defaultViewport: Viewport;
615
+ defaultThreshold: number;
616
+ captureDelay: number;
617
+ };
618
+
619
+ /** All baselines indexed by component/variant */
620
+ baselines: Record<string, Record<string, BaselineInfo>>;
621
+ }
622
+
623
+ /**
624
+ * Verification request from AI agents
625
+ */
626
+ export interface VerifyRequest {
627
+ /** Component name */
628
+ component: string;
629
+
630
+ /** Variant name */
631
+ variant: string;
632
+
633
+ /** Theme to verify against */
634
+ theme?: Theme;
635
+
636
+ /** Override diff threshold */
637
+ threshold?: number;
638
+ }
639
+
640
+ /**
641
+ * Verification result
642
+ */
643
+ export interface VerifyResult {
644
+ /** Overall verdict */
645
+ verdict: "pass" | "fail" | "error";
646
+
647
+ /** Whether diff is below threshold */
648
+ matches: boolean;
649
+
650
+ /** Percentage of pixels that differ */
651
+ diffPercentage: number;
652
+
653
+ /** Current screenshot (base64 PNG) */
654
+ screenshot: string;
655
+
656
+ /** Baseline screenshot (base64 PNG) */
657
+ baseline: string;
658
+
659
+ /** Diff image if different (base64 PNG) */
660
+ diffImage?: string;
661
+
662
+ /** Human-readable notes */
663
+ notes: string[];
664
+
665
+ /** Error message if verdict is "error" */
666
+ error?: string;
667
+
668
+ /** Performance metrics */
669
+ timing: {
670
+ renderMs: number;
671
+ captureMs: number;
672
+ diffMs: number;
673
+ totalMs: number;
674
+ };
675
+ }
676
+
677
+ /**
678
+ * Compiled segment data (JSON-serializable for AI consumption)
679
+ */
680
+ export interface CompiledSegment {
681
+ /** File path relative to project root */
682
+ filePath: string;
683
+
684
+ /** Component metadata */
685
+ meta: SegmentMeta;
686
+
687
+ /** Usage guidelines */
688
+ usage: SegmentUsage;
689
+
690
+ /** Props documentation (without render functions) */
691
+ props: Record<string, PropDefinition>;
692
+
693
+ /** Component relationships */
694
+ relations?: ComponentRelation[];
695
+
696
+ /** Variant names and descriptions (without render functions) */
697
+ variants: Array<{
698
+ name: string;
699
+ description: string;
700
+ code?: string;
701
+ figma?: string;
702
+ /** Args/props used to render this variant (for code generation) */
703
+ args?: Record<string, unknown>;
704
+ }>;
705
+
706
+ /** Agent-optimized contract metadata */
707
+ contract?: SegmentContract;
708
+
709
+ /** Provenance tracking (for generated segments) */
710
+ _generated?: SegmentGenerated;
711
+ }
712
+
713
+ /**
714
+ * Recipe definition — a named composition pattern showing how
715
+ * design system components wire together for a common use case.
716
+ */
717
+ export interface RecipeDefinition {
718
+ name: string;
719
+ description: string;
720
+ category: string;
721
+ components: string[];
722
+ code: string;
723
+ tags?: string[];
724
+ }
725
+
726
+ /**
727
+ * Compiled recipe data (JSON-serializable for AI consumption)
728
+ */
729
+ export interface CompiledRecipe {
730
+ filePath: string;
731
+ name: string;
732
+ description: string;
733
+ category: string;
734
+ components: string[];
735
+ code: string;
736
+ tags?: string[];
737
+ }
738
+
739
+ /**
740
+ * The compiled segments.json structure
741
+ */
742
+ export interface CompiledSegmentsFile {
743
+ /** Version of the schema */
744
+ version: string;
745
+
746
+ /** When this file was generated */
747
+ generatedAt: string;
748
+
749
+ /** All compiled segments indexed by component name */
750
+ segments: Record<string, CompiledSegment>;
751
+
752
+ /** All compiled recipes indexed by recipe name */
753
+ recipes?: Record<string, CompiledRecipe>;
754
+ }