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