@fragments-sdk/cli 0.7.9 → 0.7.11

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 (106) hide show
  1. package/dist/bin.js +13 -13
  2. package/dist/bin.js.map +1 -1
  3. package/dist/{chunk-CWKQQR6C.js → chunk-57OW43NL.js} +3 -3
  4. package/dist/chunk-57OW43NL.js.map +1 -0
  5. package/dist/{chunk-AA6CAHCZ.js → chunk-7CRC46HV.js} +2 -2
  6. package/dist/chunk-7CRC46HV.js.map +1 -0
  7. package/dist/{chunk-3JPJTU25.js → chunk-CRTN6BIW.js} +5 -5
  8. package/dist/chunk-CRTN6BIW.js.map +1 -0
  9. package/dist/{chunk-LHIIBI6F.js → chunk-M42XIHPV.js} +2 -2
  10. package/dist/{chunk-2EFVPE5Q.js → chunk-TQOGBAOZ.js} +2 -2
  11. package/dist/chunk-TQOGBAOZ.js.map +1 -0
  12. package/dist/core/index.d.ts +1944 -0
  13. package/dist/{core-YAPWXDZW.js → core/index.js} +5 -5
  14. package/dist/defineFragment-C6PFzZyo.d.ts +656 -0
  15. package/dist/{generate-LEBVZCCH.js → generate-ZPERYZLF.js} +4 -4
  16. package/dist/index.d.ts +4 -159
  17. package/dist/index.js +9 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/{init-4VXL3Q6N.js → init-GID2DXB3.js} +69 -7
  20. package/dist/init-GID2DXB3.js.map +1 -0
  21. package/dist/mcp-bin.js +3 -3
  22. package/dist/{scan-3NYSRF6G.js → scan-BSMLGBX4.js} +5 -5
  23. package/dist/{service-HL6TMP3B.js → service-QACVPR37.js} +3 -3
  24. package/dist/{static-viewer-KLD24I4R.js → static-viewer-2RQD5QLR.js} +3 -3
  25. package/dist/{test-Y7YZOJLE.js → test-36UELXTE.js} +3 -3
  26. package/dist/{tokens-M4FCJKBK.js → tokens-A3BZIQPB.js} +4 -4
  27. package/dist/{viewer-ZWQQ74FV.js → viewer-CNLZQUFO.js} +156 -32
  28. package/dist/viewer-CNLZQUFO.js.map +1 -0
  29. package/package.json +8 -2
  30. package/src/commands/add.ts +1 -1
  31. package/src/commands/init.ts +84 -4
  32. package/src/core/defineFragment.ts +1 -1
  33. package/src/core/figma.ts +1 -1
  34. package/src/core/index.ts +2 -2
  35. package/src/core/loader.ts +3 -3
  36. package/src/core/schema.ts +1 -1
  37. package/src/index.ts +6 -0
  38. package/src/migrate/converter.ts +1 -1
  39. package/src/service/snippet-validation.test.ts +5 -5
  40. package/src/service/snippet-validation.ts +0 -1
  41. package/src/viewer/__tests__/viewer-integration.test.ts +16 -23
  42. package/src/viewer/components/AccessibilityPanel.tsx +1 -1
  43. package/src/viewer/components/ActionsPanel.tsx +1 -1
  44. package/src/viewer/components/App.tsx +563 -166
  45. package/src/viewer/components/BottomPanel.tsx +1 -1
  46. package/src/viewer/components/CodePanel.naming.test.tsx +1 -2
  47. package/src/viewer/components/CodePanel.tsx +1 -2
  48. package/src/viewer/components/CommandPalette.tsx +1 -1
  49. package/src/viewer/components/ComponentGraph.tsx +1 -1
  50. package/src/viewer/components/ComponentHeader.tsx +1 -1
  51. package/src/viewer/components/ContractPanel.tsx +1 -1
  52. package/src/viewer/components/ErrorBoundary.tsx +1 -1
  53. package/src/viewer/components/HealthDashboard.tsx +1 -1
  54. package/src/viewer/components/HmrStatusIndicator.tsx +1 -1
  55. package/src/viewer/components/InteractionsPanel.tsx +1 -1
  56. package/src/viewer/components/IsolatedRender.tsx +1 -1
  57. package/src/viewer/components/KeyboardShortcutsHelp.tsx +1 -1
  58. package/src/viewer/components/LandingPage.tsx +1 -1
  59. package/src/viewer/components/Layout.tsx +16 -13
  60. package/src/viewer/components/LeftSidebar.tsx +105 -18
  61. package/src/viewer/components/MultiViewportPreview.tsx +1 -1
  62. package/src/viewer/components/PreviewArea.tsx +22 -13
  63. package/src/viewer/components/PreviewFrameHost.tsx +0 -4
  64. package/src/viewer/components/PreviewToolbar.tsx +1 -1
  65. package/src/viewer/components/PropsEditor.tsx +1 -1
  66. package/src/viewer/components/PropsTable.tsx +1 -1
  67. package/src/viewer/components/RightSidebar.tsx +1 -1
  68. package/src/viewer/components/ScreenshotButton.tsx +1 -1
  69. package/src/viewer/components/SkeletonLoader.tsx +1 -1
  70. package/src/viewer/components/Toast.tsx +2 -2
  71. package/src/viewer/components/TokenStylePanel.tsx +1 -1
  72. package/src/viewer/components/VariantMatrix.tsx +1 -1
  73. package/src/viewer/components/VariantTabs.tsx +1 -1
  74. package/src/viewer/components/ViewportSelector.tsx +1 -1
  75. package/src/viewer/constants/ui.ts +14 -0
  76. package/src/viewer/entry.tsx +3 -4
  77. package/src/viewer/hooks/useKeyboardShortcuts.ts +65 -17
  78. package/src/viewer/hooks/useViewSettings.ts +1 -2
  79. package/src/viewer/index.ts +1 -1
  80. package/src/viewer/preview-frame.html +6 -9
  81. package/src/viewer/server.ts +106 -9
  82. package/src/viewer/styles/globals.css +12 -51
  83. package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +110 -0
  84. package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +89 -0
  85. package/src/viewer/vendor/shared/src/DocsPageShell.tsx +119 -0
  86. package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +134 -0
  87. package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +66 -0
  88. package/src/viewer/vendor/shared/src/docs-layout.scss +28 -0
  89. package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +2 -0
  90. package/src/viewer/vendor/shared/src/index.ts +26 -0
  91. package/src/viewer/vendor/shared/src/types.ts +41 -0
  92. package/src/viewer/vite-plugin.ts +70 -9
  93. package/dist/chunk-2EFVPE5Q.js.map +0 -1
  94. package/dist/chunk-3JPJTU25.js.map +0 -1
  95. package/dist/chunk-AA6CAHCZ.js.map +0 -1
  96. package/dist/chunk-CWKQQR6C.js.map +0 -1
  97. package/dist/init-4VXL3Q6N.js.map +0 -1
  98. package/dist/viewer-ZWQQ74FV.js.map +0 -1
  99. /package/dist/{chunk-LHIIBI6F.js.map → chunk-M42XIHPV.js.map} +0 -0
  100. /package/dist/{core-YAPWXDZW.js.map → core/index.js.map} +0 -0
  101. /package/dist/{generate-LEBVZCCH.js.map → generate-ZPERYZLF.js.map} +0 -0
  102. /package/dist/{scan-3NYSRF6G.js.map → scan-BSMLGBX4.js.map} +0 -0
  103. /package/dist/{service-HL6TMP3B.js.map → service-QACVPR37.js.map} +0 -0
  104. /package/dist/{static-viewer-KLD24I4R.js.map → static-viewer-2RQD5QLR.js.map} +0 -0
  105. /package/dist/{test-Y7YZOJLE.js.map → test-36UELXTE.js.map} +0 -0
  106. /package/dist/{tokens-M4FCJKBK.js.map → tokens-A3BZIQPB.js.map} +0 -0
@@ -18,7 +18,7 @@ import {
18
18
  storyModuleToFragment,
19
19
  storyNameFromExport,
20
20
  toId
21
- } from "./chunk-2EFVPE5Q.js";
21
+ } from "../chunk-TQOGBAOZ.js";
22
22
  import {
23
23
  aiMetadataSchema,
24
24
  blockDefinitionSchema,
@@ -34,12 +34,12 @@ import {
34
34
  fragmentsConfigSchema,
35
35
  propDefinitionSchema,
36
36
  recipeDefinitionSchema
37
- } from "./chunk-AA6CAHCZ.js";
37
+ } from "../chunk-7CRC46HV.js";
38
38
  import {
39
39
  BRAND,
40
40
  DEFAULTS
41
- } from "./chunk-EKLMXTWU.js";
42
- import "./chunk-Z7EY4VHE.js";
41
+ } from "../chunk-EKLMXTWU.js";
42
+ import "../chunk-Z7EY4VHE.js";
43
43
  export {
44
44
  BRAND,
45
45
  DEFAULTS,
@@ -76,4 +76,4 @@ export {
76
76
  storyNameFromExport,
77
77
  toId
78
78
  };
79
- //# sourceMappingURL=core-YAPWXDZW.js.map
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,656 @@
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
+ }
247
+ /**
248
+ * Provenance tracking for generated fragments
249
+ * Helps distinguish human-authored from machine-generated content
250
+ */
251
+ interface FragmentGenerated {
252
+ /** Source of this fragment definition */
253
+ source: "storybook" | "manual" | "ai";
254
+ /** Original source file (e.g., "Button.stories.tsx") */
255
+ sourceFile?: string;
256
+ /** Confidence score from 0-1 (how reliable the extraction was) */
257
+ confidence?: number;
258
+ /** ISO timestamp when this was generated */
259
+ timestamp?: string;
260
+ }
261
+ /**
262
+ * AI-specific metadata for playground context generation
263
+ * Provides hints for AI code generation about component composition
264
+ */
265
+ interface AIMetadata {
266
+ /** How this component is composed with others */
267
+ compositionPattern?: "compound" | "simple" | "controlled";
268
+ /** Sub-component names (without parent prefix, e.g., "Header" not "Card.Header") */
269
+ subComponents?: string[];
270
+ /** Sub-components that must be present for valid composition */
271
+ requiredChildren?: string[];
272
+ /** Common usage patterns as JSX strings for AI reference */
273
+ commonPatterns?: string[];
274
+ }
275
+ /**
276
+ * Complete fragment definition
277
+ */
278
+ interface FragmentDefinition<TProps = unknown> {
279
+ /** The component being documented */
280
+ component: FragmentComponent<TProps>;
281
+ /** Component metadata */
282
+ meta: FragmentMeta;
283
+ /** Usage guidelines */
284
+ usage: FragmentUsage;
285
+ /** Props documentation */
286
+ props: Record<string, PropDefinition>;
287
+ /** Relationships to other components */
288
+ relations?: ComponentRelation[];
289
+ /** Component variants/examples */
290
+ variants: FragmentVariant[];
291
+ /** Agent-optimized contract metadata */
292
+ contract?: FragmentContract;
293
+ /** AI-specific metadata for playground context generation */
294
+ ai?: AIMetadata;
295
+ /** Provenance tracking (for generated fragments) */
296
+ _generated?: FragmentGenerated;
297
+ }
298
+ /**
299
+ * Registry generation options
300
+ */
301
+ interface RegistryOptions {
302
+ /** Only include components that have a corresponding .stories.tsx file */
303
+ requireStory?: boolean;
304
+ /** Only include components that are exported (public API) */
305
+ publicOnly?: boolean;
306
+ /** Maximum depth for category inference from directory structure (default: 1) */
307
+ categoryDepth?: number;
308
+ /** Include props in registry (default: false - AI can read TypeScript directly) */
309
+ includeProps?: boolean;
310
+ /** Include full fragment data in registry (default: false - reference fragmentPath instead) */
311
+ embedFragments?: boolean;
312
+ }
313
+ /**
314
+ * Design token configuration
315
+ */
316
+ interface TokenConfig {
317
+ /**
318
+ * Glob patterns for files to scan for tokens
319
+ * e.g., ["src/styles/theme.scss", "src/styles/variables.css"]
320
+ */
321
+ include: string[];
322
+ /**
323
+ * Glob patterns to exclude
324
+ * @example ["node_modules"]
325
+ */
326
+ exclude?: string[];
327
+ /**
328
+ * Map CSS selectors to theme names
329
+ * @example { ":root": "default", "[data-theme='dark']": "dark" }
330
+ */
331
+ themeSelectors?: Record<string, string>;
332
+ /** Enable token comparison in style diffs (default: true) */
333
+ enabled?: boolean;
334
+ }
335
+ /**
336
+ * CI configuration for automated compliance checks
337
+ */
338
+ interface CIConfig {
339
+ /** Minimum compliance percentage to pass (default: 80) */
340
+ minCompliance?: number;
341
+ /** Whether to fail on any visual regression */
342
+ failOnDiff?: boolean;
343
+ /** Whether to output JSON format */
344
+ jsonOutput?: boolean;
345
+ }
346
+ /**
347
+ * Snippet policy configuration.
348
+ * Controls snippet/render quality enforcement in `fragments validate`.
349
+ */
350
+ interface SnippetPolicyConfig {
351
+ /** Validation mode: warn (non-blocking) or error (blocking). Default: warn */
352
+ mode?: "warn" | "error";
353
+ /** Validate snippet strings only, or snippet strings + render functions. Default: snippet+render */
354
+ scope?: "snippet" | "snippet+render";
355
+ /** Require authored snippets to be full, copy-pasteable examples with imports. Default: true */
356
+ requireFullSnippet?: boolean;
357
+ /** Allow these external modules for JSX components in snippets/renders. */
358
+ allowedExternalModules?: string[];
359
+ }
360
+ /**
361
+ * Config file structure
362
+ */
363
+ interface FragmentsConfig {
364
+ /** Glob patterns for finding fragment/fragment files */
365
+ include: string[];
366
+ /** Glob patterns to exclude */
367
+ exclude?: string[];
368
+ /** Glob patterns for finding component files (for coverage validation) */
369
+ components?: string[];
370
+ /** Output path for compiled output */
371
+ outFile?: string;
372
+ /** Framework adapter to use */
373
+ framework?: "react" | "vue" | "svelte";
374
+ /** Figma file URL for the design system (used by `fragments link`) */
375
+ figmaFile?: string;
376
+ /** Figma access token (alternative to FIGMA_ACCESS_TOKEN env var) */
377
+ figmaToken?: string;
378
+ /** Screenshot configuration */
379
+ screenshots?: ScreenshotConfig;
380
+ /** Service configuration */
381
+ service?: ServiceConfig;
382
+ /** Registry generation options */
383
+ registry?: RegistryOptions;
384
+ /** Design token discovery and mapping configuration */
385
+ tokens?: TokenConfig;
386
+ /** CI pipeline configuration */
387
+ ci?: CIConfig;
388
+ /** Snippet/render policy validation */
389
+ snippets?: SnippetPolicyConfig;
390
+ }
391
+ /**
392
+ * Screenshot capture configuration
393
+ */
394
+ interface ScreenshotConfig {
395
+ /** Default viewport for captures */
396
+ viewport?: Viewport;
397
+ /** Diff threshold percentage (0-100) */
398
+ threshold?: number;
399
+ /** Additional delay after render before capture (ms) */
400
+ delay?: number;
401
+ /** Output directory for baselines (relative to project root) */
402
+ outputDir?: string;
403
+ /** Themes to capture */
404
+ themes?: Theme[];
405
+ }
406
+ /**
407
+ * Service configuration
408
+ */
409
+ interface ServiceConfig {
410
+ /** Browser pool size */
411
+ poolSize?: number;
412
+ /** Idle timeout before shutdown (ms) */
413
+ idleTimeout?: number;
414
+ }
415
+ /**
416
+ * Viewport dimensions
417
+ */
418
+ interface Viewport {
419
+ width: number;
420
+ height: number;
421
+ deviceScaleFactor?: number;
422
+ }
423
+ /**
424
+ * Theme identifier
425
+ */
426
+ type Theme = "light" | "dark";
427
+ /**
428
+ * Screenshot metadata
429
+ */
430
+ interface Screenshot {
431
+ /** PNG image data */
432
+ data: Buffer;
433
+ /** SHA-256 hash of image data (for change detection) */
434
+ hash: string;
435
+ /** Viewport used for capture */
436
+ viewport: Viewport;
437
+ /** When this screenshot was taken */
438
+ capturedAt: Date;
439
+ /** Capture metadata */
440
+ metadata: ScreenshotMetadata;
441
+ }
442
+ /**
443
+ * Screenshot metadata
444
+ */
445
+ interface ScreenshotMetadata {
446
+ /** Component name */
447
+ component: string;
448
+ /** Variant name */
449
+ variant: string;
450
+ /** Theme used */
451
+ theme: Theme;
452
+ /** Time to render the component (ms) */
453
+ renderTimeMs: number;
454
+ /** Time to capture the screenshot (ms) */
455
+ captureTimeMs: number;
456
+ }
457
+ /**
458
+ * Result of comparing two screenshots
459
+ */
460
+ interface DiffResult {
461
+ /** Whether images are considered matching (below threshold) */
462
+ matches: boolean;
463
+ /** Percentage of pixels that differ (0-100) */
464
+ diffPercentage: number;
465
+ /** Number of differing pixels */
466
+ diffPixelCount: number;
467
+ /** Total pixels compared */
468
+ totalPixels: number;
469
+ /** PNG image highlighting differences */
470
+ diffImage?: Buffer;
471
+ /** Bounding boxes of changed regions */
472
+ changedRegions: BoundingBox[];
473
+ /** Time taken to compute diff (ms) */
474
+ diffTimeMs: number;
475
+ }
476
+ /**
477
+ * Bounding box for changed region
478
+ */
479
+ interface BoundingBox {
480
+ x: number;
481
+ y: number;
482
+ width: number;
483
+ height: number;
484
+ }
485
+ /**
486
+ * Baseline information stored in manifest
487
+ */
488
+ interface BaselineInfo {
489
+ /** Component name */
490
+ component: string;
491
+ /** Variant name */
492
+ variant: string;
493
+ /** Theme */
494
+ theme: Theme;
495
+ /** Relative path to image file */
496
+ path: string;
497
+ /** SHA-256 hash */
498
+ hash: string;
499
+ /** Viewport used */
500
+ viewport: Viewport;
501
+ /** When captured */
502
+ capturedAt: string;
503
+ /** File size in bytes */
504
+ fileSize: number;
505
+ }
506
+ /**
507
+ * Manifest file structure
508
+ */
509
+ interface Manifest {
510
+ /** Schema version */
511
+ version: "1.0.0";
512
+ /** When manifest was generated */
513
+ generatedAt: string;
514
+ /** Configuration used for capture */
515
+ config: {
516
+ defaultViewport: Viewport;
517
+ defaultThreshold: number;
518
+ captureDelay: number;
519
+ };
520
+ /** All baselines indexed by component/variant */
521
+ baselines: Record<string, Record<string, BaselineInfo>>;
522
+ }
523
+ /**
524
+ * Verification request from AI agents
525
+ */
526
+ interface VerifyRequest {
527
+ /** Component name */
528
+ component: string;
529
+ /** Variant name */
530
+ variant: string;
531
+ /** Theme to verify against */
532
+ theme?: Theme;
533
+ /** Override diff threshold */
534
+ threshold?: number;
535
+ }
536
+ /**
537
+ * Verification result
538
+ */
539
+ interface VerifyResult {
540
+ /** Overall verdict */
541
+ verdict: "pass" | "fail" | "error";
542
+ /** Whether diff is below threshold */
543
+ matches: boolean;
544
+ /** Percentage of pixels that differ */
545
+ diffPercentage: number;
546
+ /** Current screenshot (base64 PNG) */
547
+ screenshot: string;
548
+ /** Baseline screenshot (base64 PNG) */
549
+ baseline: string;
550
+ /** Diff image if different (base64 PNG) */
551
+ diffImage?: string;
552
+ /** Human-readable notes */
553
+ notes: string[];
554
+ /** Error message if verdict is "error" */
555
+ error?: string;
556
+ /** Performance metrics */
557
+ timing: {
558
+ renderMs: number;
559
+ captureMs: number;
560
+ diffMs: number;
561
+ totalMs: number;
562
+ };
563
+ }
564
+
565
+ /**
566
+ * Block definition — a named composition pattern showing how
567
+ * design system components wire together for a common use case.
568
+ */
569
+ interface BlockDefinition {
570
+ name: string;
571
+ description: string;
572
+ category: string;
573
+ components: string[];
574
+ code: string;
575
+ tags?: string[];
576
+ }
577
+ /**
578
+ * @deprecated Use BlockDefinition instead
579
+ */
580
+ type RecipeDefinition = BlockDefinition;
581
+ /**
582
+ * @deprecated Use CompiledBlock instead
583
+ */
584
+ type CompiledRecipe = CompiledBlock;
585
+
586
+ /**
587
+ * Define a fragment for a component.
588
+ *
589
+ * This is the main API for creating fragment documentation.
590
+ * It provides runtime validation and type safety.
591
+ *
592
+ * @example
593
+ * ```tsx
594
+ * import { defineFragment } from '@fragments-sdk/cli/core';
595
+ * import { Button } from './Button';
596
+ *
597
+ * export default defineFragment({
598
+ * component: Button,
599
+ * meta: {
600
+ * name: 'Button',
601
+ * description: 'Primary action trigger',
602
+ * category: 'actions',
603
+ * },
604
+ * usage: {
605
+ * when: ['User needs to trigger an action'],
606
+ * whenNot: ['Navigation without side effects'],
607
+ * },
608
+ * props: {
609
+ * variant: {
610
+ * type: 'enum',
611
+ * values: ['primary', 'secondary'],
612
+ * default: 'primary',
613
+ * description: 'Visual style',
614
+ * },
615
+ * },
616
+ * variants: [
617
+ * {
618
+ * name: 'Default',
619
+ * description: 'Default button',
620
+ * render: () => <Button>Click me</Button>,
621
+ * },
622
+ * ],
623
+ * });
624
+ * ```
625
+ */
626
+ declare function defineFragment<TProps>(definition: FragmentDefinition<TProps>): FragmentDefinition<TProps>;
627
+ /**
628
+ * Compile a fragment definition to JSON-serializable format.
629
+ * Used for generating fragments.json for AI consumption.
630
+ */
631
+ declare function compileFragment(definition: FragmentDefinition, filePath: string): CompiledFragment;
632
+ /**
633
+ * Define a composition block.
634
+ *
635
+ * Blocks are pure data describing how design system components
636
+ * wire together for common use cases.
637
+ */
638
+ declare function defineBlock(definition: BlockDefinition): BlockDefinition;
639
+ /**
640
+ * @deprecated Use defineBlock instead
641
+ */
642
+ declare const defineRecipe: typeof defineBlock;
643
+ /**
644
+ * Compile a block definition to JSON-serializable format.
645
+ */
646
+ declare function compileBlock(definition: BlockDefinition, filePath: string): CompiledBlock;
647
+ /**
648
+ * @deprecated Use compileBlock instead
649
+ */
650
+ declare const compileRecipe: typeof compileBlock;
651
+ /**
652
+ * Type helper for extracting props type from a component
653
+ */
654
+ type InferProps<T> = T extends FragmentComponent<infer P> ? P : never;
655
+
656
+ export { type AIMetadata as A, type BlockDefinition as B, type ControlType as C, type DiffResult as D, type ScreenshotMetadata as E, type FragmentsConfig as F, type BoundingBox as G, type BaselineInfo as H, type VerifyRequest as I, type VerifyResult as J, type FigmaPropMapping as K, type TokenConfig as L, type Manifest as M, compileFragment as N, compileBlock as O, type PropType as P, defineRecipe as Q, type RelationshipType as R, type SnippetPolicyConfig as S, type Theme as T, compileRecipe as U, type VariantLoader as V, type InferProps as W, 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 FragmentComponent as j, type FragmentMeta as k, type FragmentUsage as l, type PropDefinition as m, type ComponentRelation as n, type PlayFunction as o, type PlayFunctionContext as p, type FragmentVariant as q, type RegistryOptions as r, type RecipeDefinition as s, type CompiledRecipe as t, type FragmentContract as u, type FragmentGenerated as v, type ScreenshotConfig as w, type ServiceConfig as x, type Viewport as y, type Screenshot as z };
@@ -1,10 +1,10 @@
1
1
  import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
2
2
  import {
3
3
  extractPropsFromFile
4
- } from "./chunk-CWKQQR6C.js";
4
+ } from "./chunk-57OW43NL.js";
5
5
  import "./chunk-AWYCDRPG.js";
6
- import "./chunk-2EFVPE5Q.js";
7
- import "./chunk-AA6CAHCZ.js";
6
+ import "./chunk-TQOGBAOZ.js";
7
+ import "./chunk-7CRC46HV.js";
8
8
  import {
9
9
  BRAND
10
10
  } from "./chunk-EKLMXTWU.js";
@@ -249,4 +249,4 @@ function inferStatus(filePath) {
249
249
  export {
250
250
  generate
251
251
  };
252
- //# sourceMappingURL=generate-LEBVZCCH.js.map
252
+ //# sourceMappingURL=generate-ZPERYZLF.js.map