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