@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
@@ -1,665 +0,0 @@
1
- import { ComponentType, ReactNode, JSX } from 'react';
2
- import { CompiledBlock, CompiledFragment } from '@fragments-sdk/context/types';
3
-
4
- /**
5
- * A React component that can be used in a fragment definition.
6
- * This type is intentionally broad to support various React component patterns
7
- * including FC, forwardRef, memo, and class components across different React versions.
8
- */
9
- type FragmentComponent<TProps = any> = ComponentType<TProps> | ((props: TProps) => ReactNode | JSX.Element | null);
10
- /**
11
- * Metadata about the component
12
- */
13
- interface FragmentMeta {
14
- /** Component display name */
15
- name: string;
16
- /** Brief description of the component's purpose */
17
- description: string;
18
- /** Category for organizing components (e.g., "actions", "forms", "layout") */
19
- category: string;
20
- /** Optional tags for additional categorization */
21
- tags?: string[];
22
- /** Component status */
23
- status?: "stable" | "beta" | "deprecated" | "experimental";
24
- /** Version when component was introduced */
25
- since?: string;
26
- /** External npm packages required by this component (displayed in docs Setup section) */
27
- dependencies?: Array<{
28
- name: string;
29
- version: string;
30
- reason?: string;
31
- }>;
32
- /** Figma frame URL for design verification */
33
- figma?: string;
34
- /** Figma property mappings (how Figma props map to code props) */
35
- figmaProps?: Record<string, FigmaPropMapping>;
36
- }
37
- /**
38
- * Figma property mapping types - describes how a Figma property maps to code
39
- */
40
- type FigmaPropMapping = FigmaStringMapping | FigmaBooleanMapping | FigmaEnumMapping | FigmaInstanceMapping | FigmaChildrenMapping | FigmaTextContentMapping;
41
- /** Maps a Figma text property to a string prop */
42
- interface FigmaStringMapping {
43
- __type: 'figma-string';
44
- figmaProperty: string;
45
- }
46
- /** Maps a Figma boolean property to a boolean prop (with optional value mapping) */
47
- interface FigmaBooleanMapping {
48
- __type: 'figma-boolean';
49
- figmaProperty: string;
50
- valueMapping?: {
51
- true: unknown;
52
- false: unknown;
53
- };
54
- }
55
- /** Maps a Figma variant property to an enum prop */
56
- interface FigmaEnumMapping {
57
- __type: 'figma-enum';
58
- figmaProperty: string;
59
- valueMapping: Record<string, unknown>;
60
- }
61
- /** References a nested Figma component instance */
62
- interface FigmaInstanceMapping {
63
- __type: 'figma-instance';
64
- figmaProperty: string;
65
- }
66
- /** Renders children from Figma layer names */
67
- interface FigmaChildrenMapping {
68
- __type: 'figma-children';
69
- layers: string[];
70
- }
71
- /** Extracts text content from a Figma text layer */
72
- interface FigmaTextContentMapping {
73
- __type: 'figma-text-content';
74
- layer: string;
75
- }
76
- /**
77
- * Usage guidelines for AI agents and developers
78
- */
79
- interface FragmentUsage {
80
- /** When to use this component */
81
- when: string[];
82
- /** When NOT to use this component (with alternatives) */
83
- whenNot: string[];
84
- /** Additional usage guidelines and best practices */
85
- guidelines?: string[];
86
- /** Accessibility considerations */
87
- accessibility?: string[];
88
- }
89
- /**
90
- * Prop type definitions
91
- */
92
- type PropType = {
93
- type: "string";
94
- pattern?: string;
95
- } | {
96
- type: "number";
97
- min?: number;
98
- max?: number;
99
- } | {
100
- type: "boolean";
101
- } | {
102
- type: "enum";
103
- values: readonly string[];
104
- } | {
105
- type: "function";
106
- signature?: string;
107
- } | {
108
- type: "node";
109
- } | {
110
- type: "element";
111
- } | {
112
- type: "object";
113
- shape?: Record<string, PropDefinition>;
114
- } | {
115
- type: "array";
116
- items?: PropType;
117
- } | {
118
- type: "union";
119
- types: PropType[];
120
- } | {
121
- type: "custom";
122
- typescript: string;
123
- };
124
- /**
125
- * Storybook control types for UI rendering
126
- */
127
- type ControlType = "text" | "number" | "range" | "boolean" | "select" | "multi-select" | "radio" | "inline-radio" | "check" | "inline-check" | "object" | "file" | "color" | "date";
128
- /**
129
- * Definition for a single prop
130
- */
131
- interface PropDefinition {
132
- /** The prop type */
133
- type: PropType["type"];
134
- /** For enum types, the allowed values */
135
- values?: readonly string[];
136
- /** Default value if not provided */
137
- default?: unknown;
138
- /** Description of what this prop does */
139
- description: string;
140
- /** Whether this prop is required */
141
- required?: boolean;
142
- /** Usage constraints for AI agents */
143
- constraints?: string[];
144
- /** Additional type details for complex types */
145
- typeDetails?: Omit<PropType, "type">;
146
- /** Original Storybook control type for UI rendering (e.g., "color", "date", "range") */
147
- controlType?: ControlType;
148
- /** Control options (e.g., min/max for range, presetColors for color) */
149
- controlOptions?: {
150
- min?: number;
151
- max?: number;
152
- step?: number;
153
- presetColors?: string[];
154
- };
155
- }
156
- /**
157
- * Relationship types between components
158
- */
159
- type RelationshipType = "alternative" | "sibling" | "parent" | "child" | "composition" | "complementary" | "used-by";
160
- /**
161
- * Relationship to another component
162
- */
163
- interface ComponentRelation {
164
- /** Name of the related component */
165
- component: string;
166
- /** Type of relationship */
167
- relationship: RelationshipType;
168
- /** Explanation of the relationship */
169
- note: string;
170
- }
171
- /**
172
- * Loader function type for async data loading before render
173
- */
174
- type VariantLoader = () => Promise<Record<string, unknown>>;
175
- /**
176
- * Play function context passed during interaction testing
177
- */
178
- interface PlayFunctionContext {
179
- /** The rendered canvas element containing the story */
180
- canvasElement: HTMLElement;
181
- /** Args passed to the story */
182
- args: Record<string, unknown>;
183
- /** Step function for organizing interactions */
184
- step: (name: string, fn: () => Promise<void>) => Promise<void>;
185
- }
186
- /**
187
- * Play function type for interaction testing
188
- */
189
- type PlayFunction = (context: PlayFunctionContext) => Promise<void>;
190
- /**
191
- * Options passed to variant render function
192
- */
193
- interface VariantRenderOptions {
194
- /** Props/args to override the variant defaults */
195
- args?: Record<string, unknown>;
196
- /** Data loaded from async loaders */
197
- loadedData?: Record<string, unknown>;
198
- }
199
- /**
200
- * A single variant/example of the component
201
- */
202
- interface FragmentVariant {
203
- /** Variant name */
204
- name: string;
205
- /** Description of when to use this variant */
206
- description: string;
207
- /** Render function that returns the component example
208
- * @param options - Optional args overrides and loaded data
209
- */
210
- render: (options?: VariantRenderOptions) => ReactNode;
211
- /** Optional code string for display (auto-generated if not provided) */
212
- code?: string;
213
- /** Figma frame URL for this specific variant (overrides meta.figma) */
214
- figma?: string;
215
- /** Whether this variant has a Storybook play function (for display purposes) */
216
- hasPlayFunction?: boolean;
217
- /** The actual play function for interaction testing */
218
- play?: PlayFunction;
219
- /** Storybook story ID for this variant (generated by @storybook/csf toId) */
220
- storyId?: string;
221
- /** Optional tags for this variant (inherited from story tags) */
222
- tags?: string[];
223
- /** Async loaders to execute before rendering (from Storybook loaders) */
224
- loaders?: VariantLoader[];
225
- /** The args/props used to render this variant (for code generation) */
226
- args?: Record<string, unknown>;
227
- }
228
- /**
229
- * Agent-optimized contract metadata
230
- * Provides compact, structured data for AI code generation
231
- */
232
- interface FragmentContract {
233
- /** Short prop descriptions for agents (e.g., "variant: primary|secondary (required)") */
234
- propsSummary?: string[];
235
- /** Accessibility rule IDs for lookup in glossary (e.g., "A11Y_BTN_LABEL") */
236
- a11yRules?: string[];
237
- /** Banned patterns in codebase - triggers warnings during code review */
238
- bans?: Array<{
239
- /** Pattern to match (regex string or literal) */
240
- pattern: string;
241
- /** Message explaining why this pattern is banned and what to use instead */
242
- message: string;
243
- }>;
244
- /** Scenario tags for use-case matching (e.g., "form.submit", "navigation.primary") */
245
- scenarioTags?: string[];
246
- /** Per-component performance budget override in bytes (gzipped). Overrides global budget. */
247
- performanceBudget?: number;
248
- }
249
- /**
250
- * Provenance tracking for generated fragments
251
- * Helps distinguish human-authored from machine-generated content
252
- */
253
- interface FragmentGenerated {
254
- /** Source of this fragment definition */
255
- source: "storybook" | "manual" | "ai";
256
- /** Original source file (e.g., "Button.stories.tsx") */
257
- sourceFile?: string;
258
- /** Confidence score from 0-1 (how reliable the extraction was) */
259
- confidence?: number;
260
- /** ISO timestamp when this was generated */
261
- timestamp?: string;
262
- }
263
- /**
264
- * AI-specific metadata for playground context generation
265
- * Provides hints for AI code generation about component composition
266
- */
267
- interface AIMetadata {
268
- /** How this component is composed with others */
269
- compositionPattern?: "compound" | "simple" | "controlled";
270
- /** Sub-component names (without parent prefix, e.g., "Header" not "Card.Header") */
271
- subComponents?: string[];
272
- /** Sub-components that must be present for valid composition */
273
- requiredChildren?: string[];
274
- /** Common usage patterns as JSX strings for AI reference */
275
- commonPatterns?: string[];
276
- }
277
- /**
278
- * Complete fragment definition
279
- */
280
- interface FragmentDefinition<TProps = unknown> {
281
- /** The component being documented */
282
- component: FragmentComponent<TProps>;
283
- /** Component metadata */
284
- meta: FragmentMeta;
285
- /** Usage guidelines */
286
- usage: FragmentUsage;
287
- /** Props documentation */
288
- props: Record<string, PropDefinition>;
289
- /** Relationships to other components */
290
- relations?: ComponentRelation[];
291
- /** Component variants/examples */
292
- variants: FragmentVariant[];
293
- /** Agent-optimized contract metadata */
294
- contract?: FragmentContract;
295
- /** AI-specific metadata for playground context generation */
296
- ai?: AIMetadata;
297
- /** Provenance tracking (for generated fragments) */
298
- _generated?: FragmentGenerated;
299
- }
300
- /**
301
- * Registry generation options
302
- */
303
- interface RegistryOptions {
304
- /** Only include components that have a corresponding .stories.tsx file */
305
- requireStory?: boolean;
306
- /** Only include components that are exported (public API) */
307
- publicOnly?: boolean;
308
- /** Maximum depth for category inference from directory structure (default: 1) */
309
- categoryDepth?: number;
310
- /** Include props in registry (default: false - AI can read TypeScript directly) */
311
- includeProps?: boolean;
312
- /** Include full fragment data in registry (default: false - reference fragmentPath instead) */
313
- embedFragments?: boolean;
314
- }
315
- /**
316
- * Design token configuration
317
- */
318
- interface TokenConfig {
319
- /**
320
- * Glob patterns for files to scan for tokens
321
- * e.g., ["src/styles/theme.scss", "src/styles/variables.css"]
322
- */
323
- include: string[];
324
- /**
325
- * Glob patterns to exclude
326
- * @example ["node_modules"]
327
- */
328
- exclude?: string[];
329
- /**
330
- * Map CSS selectors to theme names
331
- * @example { ":root": "default", "[data-theme='dark']": "dark" }
332
- */
333
- themeSelectors?: Record<string, string>;
334
- /** Enable token comparison in style diffs (default: true) */
335
- enabled?: boolean;
336
- }
337
- /**
338
- * CI configuration for automated compliance checks
339
- */
340
- interface CIConfig {
341
- /** Minimum compliance percentage to pass (default: 80) */
342
- minCompliance?: number;
343
- /** Whether to fail on any visual regression */
344
- failOnDiff?: boolean;
345
- /** Whether to output JSON format */
346
- jsonOutput?: boolean;
347
- }
348
- /**
349
- * Snippet policy configuration.
350
- * Controls snippet/render quality enforcement in `fragments validate`.
351
- */
352
- interface SnippetPolicyConfig {
353
- /** Validation mode: warn (non-blocking) or error (blocking). Default: warn */
354
- mode?: "warn" | "error";
355
- /** Validate snippet strings only, or snippet strings + render functions. Default: snippet+render */
356
- scope?: "snippet" | "snippet+render";
357
- /** Require authored snippets to be full, copy-pasteable examples with imports. Default: true */
358
- requireFullSnippet?: boolean;
359
- /** Allow these external modules for JSX components in snippets/renders. */
360
- allowedExternalModules?: string[];
361
- }
362
- /**
363
- * Config file structure
364
- */
365
- interface FragmentsConfig {
366
- /** Glob patterns for finding fragment/fragment files */
367
- include: string[];
368
- /** Glob patterns to exclude */
369
- exclude?: string[];
370
- /** Glob patterns for finding component files (for coverage validation) */
371
- components?: string[];
372
- /** Output path for compiled output */
373
- outFile?: string;
374
- /** Framework adapter to use */
375
- framework?: "react" | "vue" | "svelte";
376
- /** Figma file URL for the design system (used by `fragments link`) */
377
- figmaFile?: string;
378
- /** Figma access token (alternative to FIGMA_ACCESS_TOKEN env var) */
379
- figmaToken?: string;
380
- /** Screenshot configuration */
381
- screenshots?: ScreenshotConfig;
382
- /** Service configuration */
383
- service?: ServiceConfig;
384
- /** Registry generation options */
385
- registry?: RegistryOptions;
386
- /** Design token discovery and mapping configuration */
387
- tokens?: TokenConfig;
388
- /** CI pipeline configuration */
389
- ci?: CIConfig;
390
- /** Snippet/render policy validation */
391
- snippets?: SnippetPolicyConfig;
392
- /** Performance budgets: preset name or custom config */
393
- performance?: string | {
394
- preset?: string;
395
- budgets?: {
396
- bundleSize?: number;
397
- };
398
- };
399
- }
400
- /**
401
- * Screenshot capture configuration
402
- */
403
- interface ScreenshotConfig {
404
- /** Default viewport for captures */
405
- viewport?: Viewport;
406
- /** Diff threshold percentage (0-100) */
407
- threshold?: number;
408
- /** Additional delay after render before capture (ms) */
409
- delay?: number;
410
- /** Output directory for baselines (relative to project root) */
411
- outputDir?: string;
412
- /** Themes to capture */
413
- themes?: Theme[];
414
- }
415
- /**
416
- * Service configuration
417
- */
418
- interface ServiceConfig {
419
- /** Browser pool size */
420
- poolSize?: number;
421
- /** Idle timeout before shutdown (ms) */
422
- idleTimeout?: number;
423
- }
424
- /**
425
- * Viewport dimensions
426
- */
427
- interface Viewport {
428
- width: number;
429
- height: number;
430
- deviceScaleFactor?: number;
431
- }
432
- /**
433
- * Theme identifier
434
- */
435
- type Theme = "light" | "dark";
436
- /**
437
- * Screenshot metadata
438
- */
439
- interface Screenshot {
440
- /** PNG image data */
441
- data: Buffer;
442
- /** SHA-256 hash of image data (for change detection) */
443
- hash: string;
444
- /** Viewport used for capture */
445
- viewport: Viewport;
446
- /** When this screenshot was taken */
447
- capturedAt: Date;
448
- /** Capture metadata */
449
- metadata: ScreenshotMetadata;
450
- }
451
- /**
452
- * Screenshot metadata
453
- */
454
- interface ScreenshotMetadata {
455
- /** Component name */
456
- component: string;
457
- /** Variant name */
458
- variant: string;
459
- /** Theme used */
460
- theme: Theme;
461
- /** Time to render the component (ms) */
462
- renderTimeMs: number;
463
- /** Time to capture the screenshot (ms) */
464
- captureTimeMs: number;
465
- }
466
- /**
467
- * Result of comparing two screenshots
468
- */
469
- interface DiffResult {
470
- /** Whether images are considered matching (below threshold) */
471
- matches: boolean;
472
- /** Percentage of pixels that differ (0-100) */
473
- diffPercentage: number;
474
- /** Number of differing pixels */
475
- diffPixelCount: number;
476
- /** Total pixels compared */
477
- totalPixels: number;
478
- /** PNG image highlighting differences */
479
- diffImage?: Buffer;
480
- /** Bounding boxes of changed regions */
481
- changedRegions: BoundingBox[];
482
- /** Time taken to compute diff (ms) */
483
- diffTimeMs: number;
484
- }
485
- /**
486
- * Bounding box for changed region
487
- */
488
- interface BoundingBox {
489
- x: number;
490
- y: number;
491
- width: number;
492
- height: number;
493
- }
494
- /**
495
- * Baseline information stored in manifest
496
- */
497
- interface BaselineInfo {
498
- /** Component name */
499
- component: string;
500
- /** Variant name */
501
- variant: string;
502
- /** Theme */
503
- theme: Theme;
504
- /** Relative path to image file */
505
- path: string;
506
- /** SHA-256 hash */
507
- hash: string;
508
- /** Viewport used */
509
- viewport: Viewport;
510
- /** When captured */
511
- capturedAt: string;
512
- /** File size in bytes */
513
- fileSize: number;
514
- }
515
- /**
516
- * Manifest file structure
517
- */
518
- interface Manifest {
519
- /** Schema version */
520
- version: "1.0.0";
521
- /** When manifest was generated */
522
- generatedAt: string;
523
- /** Configuration used for capture */
524
- config: {
525
- defaultViewport: Viewport;
526
- defaultThreshold: number;
527
- captureDelay: number;
528
- };
529
- /** All baselines indexed by component/variant */
530
- baselines: Record<string, Record<string, BaselineInfo>>;
531
- }
532
- /**
533
- * Verification request from AI agents
534
- */
535
- interface VerifyRequest {
536
- /** Component name */
537
- component: string;
538
- /** Variant name */
539
- variant: string;
540
- /** Theme to verify against */
541
- theme?: Theme;
542
- /** Override diff threshold */
543
- threshold?: number;
544
- }
545
- /**
546
- * Verification result
547
- */
548
- interface VerifyResult {
549
- /** Overall verdict */
550
- verdict: "pass" | "fail" | "error";
551
- /** Whether diff is below threshold */
552
- matches: boolean;
553
- /** Percentage of pixels that differ */
554
- diffPercentage: number;
555
- /** Current screenshot (base64 PNG) */
556
- screenshot: string;
557
- /** Baseline screenshot (base64 PNG) */
558
- baseline: string;
559
- /** Diff image if different (base64 PNG) */
560
- diffImage?: string;
561
- /** Human-readable notes */
562
- notes: string[];
563
- /** Error message if verdict is "error" */
564
- error?: string;
565
- /** Performance metrics */
566
- timing: {
567
- renderMs: number;
568
- captureMs: number;
569
- diffMs: number;
570
- totalMs: number;
571
- };
572
- }
573
-
574
- /**
575
- * Block definition — a named composition pattern showing how
576
- * design system components wire together for a common use case.
577
- */
578
- interface BlockDefinition {
579
- name: string;
580
- description: string;
581
- category: string;
582
- components: string[];
583
- code: string;
584
- tags?: string[];
585
- }
586
- /**
587
- * @deprecated Use BlockDefinition instead
588
- */
589
- type RecipeDefinition = BlockDefinition;
590
- /**
591
- * @deprecated Use CompiledBlock instead
592
- */
593
- type CompiledRecipe = CompiledBlock;
594
-
595
- /**
596
- * Define a fragment for a component.
597
- *
598
- * This is the main API for creating fragment documentation.
599
- * It provides runtime validation and type safety.
600
- *
601
- * @example
602
- * ```tsx
603
- * import { defineFragment } from '@fragments-sdk/cli/core';
604
- * import { Button } from './Button';
605
- *
606
- * export default defineFragment({
607
- * component: Button,
608
- * meta: {
609
- * name: 'Button',
610
- * description: 'Primary action trigger',
611
- * category: 'actions',
612
- * },
613
- * usage: {
614
- * when: ['User needs to trigger an action'],
615
- * whenNot: ['Navigation without side effects'],
616
- * },
617
- * props: {
618
- * variant: {
619
- * type: 'enum',
620
- * values: ['primary', 'secondary'],
621
- * default: 'primary',
622
- * description: 'Visual style',
623
- * },
624
- * },
625
- * variants: [
626
- * {
627
- * name: 'Default',
628
- * description: 'Default button',
629
- * render: () => <Button>Click me</Button>,
630
- * },
631
- * ],
632
- * });
633
- * ```
634
- */
635
- declare function defineFragment<TProps>(definition: FragmentDefinition<TProps>): FragmentDefinition<TProps>;
636
- /**
637
- * Compile a fragment definition to JSON-serializable format.
638
- * Used for generating fragments.json for AI consumption.
639
- */
640
- declare function compileFragment(definition: FragmentDefinition, filePath: string): CompiledFragment;
641
- /**
642
- * Define a composition block.
643
- *
644
- * Blocks are pure data describing how design system components
645
- * wire together for common use cases.
646
- */
647
- declare function defineBlock(definition: BlockDefinition): BlockDefinition;
648
- /**
649
- * @deprecated Use defineBlock instead
650
- */
651
- declare const defineRecipe: typeof defineBlock;
652
- /**
653
- * Compile a block definition to JSON-serializable format.
654
- */
655
- declare function compileBlock(definition: BlockDefinition, filePath: string): CompiledBlock;
656
- /**
657
- * @deprecated Use compileBlock instead
658
- */
659
- declare const compileRecipe: typeof compileBlock;
660
- /**
661
- * Type helper for extracting props type from a component
662
- */
663
- type InferProps<T> = T extends FragmentComponent<infer P> ? P : never;
664
-
665
- export { type AIMetadata as A, type BlockDefinition as B, type ControlType as C, type DiffResult as D, type Screenshot as E, type FragmentsConfig as F, type ScreenshotMetadata as G, type BoundingBox as H, type BaselineInfo as I, type VerifyRequest as J, type VerifyResult as K, type FigmaPropMapping as L, type Manifest as M, type TokenConfig as N, compileFragment as O, type PropType as P, compileBlock as Q, type RelationshipType as R, type SnippetPolicyConfig as S, type Theme as T, defineRecipe as U, type VariantLoader as V, compileRecipe as W, type InferProps as X, defineBlock as a, type FragmentDefinition as b, type FigmaStringMapping as c, defineFragment as d, type FigmaBooleanMapping as e, type FigmaEnumMapping as f, type FigmaInstanceMapping as g, type FigmaChildrenMapping as h, type FigmaTextContentMapping as i, type VariantRenderOptions as j, type FragmentComponent as k, type FragmentMeta as l, type FragmentUsage as m, type PropDefinition as n, type ComponentRelation as o, type PlayFunction as p, type PlayFunctionContext as q, type FragmentVariant as r, type RegistryOptions as s, type RecipeDefinition as t, type CompiledRecipe as u, type FragmentContract as v, type FragmentGenerated as w, type ScreenshotConfig as x, type ServiceConfig as y, type Viewport as z };