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