@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/performance-presets.ts","../src/schema.ts","../src/defineFragment.ts","../src/storyAdapter.ts","../src/storybook-csf.ts","../src/storyFilters.ts","../src/context.ts","../src/figma.ts","../src/token-parser.ts","../src/composition.ts","../src/preview-runtime.tsx"],"sourcesContent":["/**\n * Brand constants for easy rebranding if domain availability requires it.\n * All naming throughout the codebase should reference these constants.\n */\nexport const BRAND = {\n /** Display name (e.g., \"Fragments\") */\n name: \"Fragments\",\n\n /** Lowercase name for file paths and CLI (e.g., \"fragments\") */\n nameLower: \"fragments\",\n\n /** File extension for fragment definition files (e.g., \".fragment.tsx\") */\n fileExtension: \".fragment.tsx\",\n\n /** Legacy file extension for segments (still supported for migration) */\n legacyFileExtension: \".segment.tsx\",\n\n /** JSON file extension for compiled output */\n jsonExtension: \".fragment.json\",\n\n /** Default output file name (e.g., \"fragments.json\") */\n outFile: \"fragments.json\",\n\n /** Config file name (e.g., \"fragments.config.ts\") */\n configFile: \"fragments.config.ts\",\n\n /** Legacy config file name (still supported for migration) */\n legacyConfigFile: \"segments.config.ts\",\n\n /** CLI command name (e.g., \"fragments\") */\n cliCommand: \"fragments\",\n\n /** Package scope (e.g., \"@fragments\") */\n packageScope: \"@fragments\",\n\n /** Directory for storing fragments, registry, and cache */\n dataDir: \".fragments\",\n\n /** Components subdirectory within .fragments/ */\n componentsDir: \"components\",\n\n /** Registry file name */\n registryFile: \"registry.json\",\n\n /** Context file name (AI-ready markdown) */\n contextFile: \"context.md\",\n\n /** Screenshots subdirectory */\n screenshotsDir: \"screenshots\",\n\n /** Cache subdirectory (gitignored) */\n cacheDir: \"cache\",\n\n /** Diff output subdirectory (gitignored) */\n diffDir: \"diff\",\n\n /** Manifest filename */\n manifestFile: \"manifest.json\",\n\n /** Prefix for localStorage keys (e.g., \"fragments-\") */\n storagePrefix: \"fragments-\",\n\n /** Static viewer HTML file name */\n viewerHtmlFile: \"fragments-viewer.html\",\n\n /** MCP tool name prefix (e.g., \"fragments_\") */\n mcpToolPrefix: \"fragments_\",\n\n /** File extension for block definition files */\n blockFileExtension: \".block.ts\",\n\n /** @deprecated Use blockFileExtension instead */\n recipeFileExtension: \".recipe.ts\",\n\n /** Vite plugin namespace */\n vitePluginNamespace: \"fragments-core-shim\",\n} as const;\n\nexport type Brand = typeof BRAND;\n\n/**\n * Default configuration values for the service.\n * These can be overridden in fragments.config.ts\n */\nexport const DEFAULTS = {\n /** Default viewport dimensions */\n viewport: {\n width: 1280,\n height: 800,\n },\n\n /** Default diff threshold (percentage) */\n diffThreshold: 5,\n\n /** Browser pool size */\n poolSize: 3,\n\n /** Idle timeout before browser shutdown (ms) - 5 minutes */\n idleTimeoutMs: 5 * 60 * 1000,\n\n /** Delay after render before capture (ms) */\n captureDelayMs: 100,\n\n /** Font loading timeout (ms) */\n fontTimeoutMs: 3000,\n\n /** Default theme */\n theme: \"light\" as const,\n\n /** Dev server port */\n port: 6006,\n} as const;\n\nexport type Defaults = typeof DEFAULTS;\n","/**\n * Performance budget presets and classification utilities.\n *\n * ESLint model: global defaults, zero-config, auto-measurement.\n * Users configure 0-3 numbers. Per-component overrides are the `eslint-disable` equivalent.\n */\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface PerformanceBudgets {\n /** Maximum gzipped bundle size in bytes */\n bundleSize: number;\n}\n\nexport interface PerformanceConfig {\n preset: string;\n budgets: PerformanceBudgets;\n}\n\nexport type ComplexityTier = 'lightweight' | 'moderate' | 'heavy';\n\nexport interface PerformanceData {\n /** Gzipped bundle size in bytes */\n bundleSize: number;\n /** Raw (minified, not gzipped) bundle size in bytes */\n rawSize: number;\n /** Complexity classification */\n complexity: ComplexityTier;\n /** Percentage of budget used (0-100+) */\n budgetPercent: number;\n /** Whether the component exceeds its budget */\n overBudget: boolean;\n /** ISO timestamp when measured */\n measuredAt: string;\n}\n\nexport interface PerformanceSummary {\n /** Preset name used */\n preset: string;\n /** Budget applied in bytes */\n budget: number;\n /** Total components measured */\n total: number;\n /** Number of components over budget */\n overBudget: number;\n /** Distribution by tier */\n tiers: Record<ComplexityTier, number>;\n}\n\n// ---------------------------------------------------------------------------\n// Presets\n// ---------------------------------------------------------------------------\n\nconst PRESETS: Record<string, PerformanceBudgets> = {\n strict: { bundleSize: 8 * 1024 }, // 8KB gzipped\n standard: { bundleSize: 15 * 1024 }, // 15KB gzipped\n relaxed: { bundleSize: 30 * 1024 }, // 30KB gzipped\n};\n\nexport const PRESET_NAMES = Object.keys(PRESETS) as readonly string[];\n\n// ---------------------------------------------------------------------------\n// Resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve a performance config from user input.\n * Accepts a preset name string or a custom config object.\n */\nexport function resolvePerformanceConfig(\n input: string | { preset?: string; budgets?: Partial<PerformanceBudgets> } | undefined\n): PerformanceConfig {\n if (!input) {\n return { preset: 'standard', budgets: PRESETS.standard };\n }\n\n if (typeof input === 'string') {\n const budgets = PRESETS[input];\n if (!budgets) {\n throw new Error(\n `Unknown performance preset \"${input}\". Available: ${PRESET_NAMES.join(', ')}`\n );\n }\n return { preset: input, budgets };\n }\n\n const presetName = input.preset ?? 'standard';\n const baseBudgets = PRESETS[presetName];\n if (!baseBudgets) {\n throw new Error(\n `Unknown performance preset \"${presetName}\". Available: ${PRESET_NAMES.join(', ')}`\n );\n }\n\n return {\n preset: presetName,\n budgets: {\n bundleSize: input.budgets?.bundleSize ?? baseBudgets.bundleSize,\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Classification\n// ---------------------------------------------------------------------------\n\n/**\n * Classify a component's complexity based on gzipped bundle size.\n *\n * - lightweight: < 5KB — simple, leaf components\n * - moderate: < 15KB — typical composed components\n * - heavy: >= 15KB — complex widgets with dependencies\n */\nexport function classifyComplexity(gzipBytes: number): ComplexityTier {\n if (gzipBytes < 5 * 1024) return 'lightweight';\n if (gzipBytes < 15 * 1024) return 'moderate';\n return 'heavy';\n}\n\n// ---------------------------------------------------------------------------\n// Formatting helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Format bytes to a human-readable string (e.g. \"2.1KB\", \"15.3KB\").\n */\nexport function formatBytes(bytes: number): string {\n if (bytes < 1024) return `${bytes}B`;\n const kb = bytes / 1024;\n return kb < 10 ? `${kb.toFixed(1)}KB` : `${Math.round(kb)}KB`;\n}\n\n/**\n * Create a visual budget bar for terminal output.\n */\nexport function budgetBar(percent: number, width = 20): string {\n const filled = Math.min(Math.round((percent / 100) * width), width);\n const bar = '█'.repeat(filled) + '░'.repeat(width - filled);\n return percent > 100 ? `\\x1b[31m${bar}\\x1b[0m` : `\\x1b[32m${bar}\\x1b[0m`;\n}\n","import { z } from 'zod';\n\n/**\n * Zod schemas for runtime validation of fragment definitions\n */\n\n// Figma property mapping schemas\nconst figmaStringMappingSchema = z.object({\n __type: z.literal('figma-string'),\n figmaProperty: z.string().min(1),\n});\n\nconst figmaBooleanMappingSchema = z.object({\n __type: z.literal('figma-boolean'),\n figmaProperty: z.string().min(1),\n valueMapping: z.object({ true: z.unknown(), false: z.unknown() }).optional(),\n});\n\nconst figmaEnumMappingSchema = z.object({\n __type: z.literal('figma-enum'),\n figmaProperty: z.string().min(1),\n valueMapping: z.record(z.unknown()),\n});\n\nconst figmaInstanceMappingSchema = z.object({\n __type: z.literal('figma-instance'),\n figmaProperty: z.string().min(1),\n});\n\nconst figmaChildrenMappingSchema = z.object({\n __type: z.literal('figma-children'),\n layers: z.array(z.string().min(1)),\n});\n\nconst figmaTextContentMappingSchema = z.object({\n __type: z.literal('figma-text-content'),\n layer: z.string().min(1),\n});\n\nexport const figmaPropMappingSchema = z.discriminatedUnion('__type', [\n figmaStringMappingSchema,\n figmaBooleanMappingSchema,\n figmaEnumMappingSchema,\n figmaInstanceMappingSchema,\n figmaChildrenMappingSchema,\n figmaTextContentMappingSchema,\n]);\n\nexport const fragmentMetaSchema = z.object({\n name: z.string().min(1),\n description: z.string().min(1),\n category: z.string().min(1),\n tags: z.array(z.string()).optional(),\n status: z.enum(['stable', 'beta', 'deprecated', 'experimental']).optional(),\n since: z.string().optional(),\n dependencies: z.array(z.object({\n name: z.string().min(1),\n version: z.string().min(1),\n reason: z.string().optional(),\n })).optional(),\n figma: z.string().url().optional(),\n figmaProps: z.record(figmaPropMappingSchema).optional(),\n});\n\nexport const fragmentUsageSchema = z.object({\n when: z.array(z.string()),\n whenNot: z.array(z.string()),\n guidelines: z.array(z.string()).optional(),\n accessibility: z.array(z.string()).optional(),\n});\n\nexport const propTypeSchema: z.ZodType<string> = z.enum([\n 'string',\n 'number',\n 'boolean',\n 'enum',\n 'function',\n 'node',\n 'element',\n 'object',\n 'array',\n 'union',\n 'custom',\n]);\n\nexport const propDefinitionSchema = z.object({\n type: propTypeSchema,\n values: z.array(z.string()).readonly().optional(),\n default: z.unknown().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n constraints: z.array(z.string()).optional(),\n typeDetails: z.record(z.unknown()).optional(),\n});\n\nexport const relationshipTypeSchema = z.enum([\n 'alternative',\n 'sibling',\n 'parent',\n 'child',\n 'composition',\n 'complementary',\n 'used-by',\n]);\n\nexport const componentRelationSchema = z.object({\n component: z.string().min(1),\n relationship: relationshipTypeSchema,\n note: z.string().min(1),\n});\n\nexport const fragmentVariantSchema = z.object({\n name: z.string().min(1),\n description: z.string().min(1),\n render: z.function().returns(z.unknown()),\n code: z.string().optional(),\n figma: z.string().url().optional(),\n});\n\n/**\n * Schema for banned patterns in codebase\n */\nexport const fragmentBanSchema = z.object({\n pattern: z.string().min(1),\n message: z.string().min(1),\n});\n\n/**\n * Schema for agent-optimized contract metadata\n */\nexport const fragmentContractSchema = z.object({\n propsSummary: z.array(z.string()).optional(),\n a11yRules: z.array(z.string()).optional(),\n bans: z.array(fragmentBanSchema).optional(),\n scenarioTags: z.array(z.string()).optional(),\n performanceBudget: z.number().positive().optional(),\n});\n\n/**\n * Schema for provenance tracking of generated fragments\n */\nexport const fragmentGeneratedSchema = z.object({\n source: z.enum(['storybook', 'manual', 'ai']),\n sourceFile: z.string().optional(),\n confidence: z.number().min(0).max(1).optional(),\n timestamp: z.string().datetime().optional(),\n});\n\n/**\n * Schema for AI-specific metadata for playground context generation\n */\nexport const aiMetadataSchema = z.object({\n compositionPattern: z.enum(['compound', 'simple', 'controlled', 'wrapper']).optional(),\n subComponents: z.array(z.string()).optional(),\n requiredChildren: z.array(z.string()).optional(),\n commonPatterns: z.array(z.string()).optional(),\n});\n\n/**\n * Schema for block definitions\n */\nexport const blockDefinitionSchema = z.object({\n name: z.string().min(1),\n description: z.string().min(1),\n category: z.string().min(1),\n components: z.array(z.string().min(1)).min(1),\n code: z.string().min(1),\n tags: z.array(z.string()).optional(),\n});\n\nexport const fragmentDefinitionSchema = z.object({\n component: z.any(), // Allow any component type (function, class, forwardRef, etc.)\n meta: fragmentMetaSchema,\n usage: fragmentUsageSchema,\n props: z.record(propDefinitionSchema),\n relations: z.array(componentRelationSchema).optional(),\n variants: z.array(fragmentVariantSchema), // Allow empty variants array\n contract: fragmentContractSchema.optional(),\n ai: aiMetadataSchema.optional(),\n _generated: fragmentGeneratedSchema.optional(),\n});\n\n/**\n * Config schema - validates required fields, passes through optional config objects.\n * Type definitions are in types.ts - schema just ensures basic structure.\n */\nexport const fragmentsConfigSchema = z.object({\n include: z.array(z.string()).min(1),\n exclude: z.array(z.string()).optional(),\n components: z.array(z.string()).optional(),\n outFile: z.string().optional(),\n framework: z.enum(['react', 'vue', 'svelte']).optional(),\n figmaFile: z.string().url().optional(),\n figmaToken: z.string().optional(),\n screenshots: z.object({}).passthrough().optional(),\n service: z.object({}).passthrough().optional(),\n registry: z.object({}).passthrough().optional(),\n tokens: z.object({\n include: z.array(z.string()).min(1),\n }).passthrough().optional(),\n snippets: z.object({\n mode: z.enum(['warn', 'error']).optional(),\n scope: z.enum(['snippet', 'snippet+render']).optional(),\n requireFullSnippet: z.boolean().optional(),\n allowedExternalModules: z.array(z.string().min(1)).optional(),\n }).optional(),\n performance: z.union([\n z.enum(['strict', 'standard', 'relaxed']),\n z.object({\n preset: z.enum(['strict', 'standard', 'relaxed']).optional(),\n budgets: z.object({\n bundleSize: z.number().positive().optional(),\n }).optional(),\n }),\n ]).optional(),\n storybook: z.object({\n exclude: z.array(z.string()).optional(),\n include: z.array(z.string()).optional(),\n excludeDeprecated: z.boolean().optional(),\n excludeTests: z.boolean().optional(),\n excludeSvgIcons: z.boolean().optional(),\n excludeSubComponents: z.boolean().optional(),\n }).optional(),\n});\n\n/**\n * @deprecated Use blockDefinitionSchema instead\n */\nexport const recipeDefinitionSchema = blockDefinitionSchema;\n","import type { FragmentDefinition, CompiledFragment, FragmentComponent, BlockDefinition, CompiledBlock } from './types.js';\nimport { fragmentDefinitionSchema, blockDefinitionSchema } from './schema.js';\n\n/**\n * Define a fragment for a component.\n *\n * This is the main API for creating fragment documentation.\n * It provides runtime validation and type safety.\n *\n * @example\n * ```tsx\n * import { defineFragment } from '@fragments-sdk/cli/core';\n * import { Button } from './Button';\n *\n * export default defineFragment({\n * component: Button,\n * meta: {\n * name: 'Button',\n * description: 'Primary action trigger',\n * category: 'actions',\n * },\n * usage: {\n * when: ['User needs to trigger an action'],\n * whenNot: ['Navigation without side effects'],\n * },\n * props: {\n * variant: {\n * type: 'enum',\n * values: ['primary', 'secondary'],\n * default: 'primary',\n * description: 'Visual style',\n * },\n * },\n * variants: [\n * {\n * name: 'Default',\n * description: 'Default button',\n * render: () => <Button>Click me</Button>,\n * },\n * ],\n * });\n * ```\n */\nexport function defineFragment<TProps>(\n definition: FragmentDefinition<TProps>\n): FragmentDefinition<TProps> {\n // Validate at runtime in development\n if (process.env.NODE_ENV !== 'production') {\n const result = fragmentDefinitionSchema.safeParse(definition);\n if (!result.success) {\n const errors = result.error.errors\n .map((e) => ` - ${e.path.join('.')}: ${e.message}`)\n .join('\\n');\n throw new Error(\n `Invalid fragment definition for \"${definition.meta?.name || 'unknown'}\":\\n${errors}`\n );\n }\n }\n\n return definition;\n}\n\n/**\n * Compile a fragment definition to JSON-serializable format.\n * Used for generating fragments.json for AI consumption.\n */\nexport function compileFragment(\n definition: FragmentDefinition,\n filePath: string\n): CompiledFragment {\n return {\n filePath,\n meta: definition.meta,\n usage: definition.usage,\n props: definition.props,\n relations: definition.relations,\n variants: definition.variants.map((v) => ({\n name: v.name,\n description: v.description,\n code: v.code,\n figma: v.figma,\n })),\n contract: definition.contract,\n _generated: definition._generated,\n };\n}\n\n/**\n * Define a composition block.\n *\n * Blocks are pure data describing how design system components\n * wire together for common use cases.\n */\nexport function defineBlock(definition: BlockDefinition): BlockDefinition {\n if (process.env.NODE_ENV !== 'production') {\n const result = blockDefinitionSchema.safeParse(definition);\n if (!result.success) {\n const errors = result.error.errors\n .map((e) => ` - ${e.path.join('.')}: ${e.message}`)\n .join('\\n');\n throw new Error(\n `Invalid block definition for \"${definition.name || 'unknown'}\":\\n${errors}`\n );\n }\n }\n\n return definition;\n}\n\n/**\n * @deprecated Use defineBlock instead\n */\nexport const defineRecipe = defineBlock;\n\n/**\n * Compile a block definition to JSON-serializable format.\n */\nexport function compileBlock(\n definition: BlockDefinition,\n filePath: string\n): CompiledBlock {\n return {\n filePath,\n name: definition.name,\n description: definition.description,\n category: definition.category,\n components: definition.components,\n code: definition.code,\n tags: definition.tags,\n };\n}\n\n/**\n * @deprecated Use compileBlock instead\n */\nexport const compileRecipe = compileBlock;\n\n/**\n * Type helper for extracting props type from a component\n */\nexport type InferProps<T> = T extends FragmentComponent<infer P> ? P : never;\n","/**\n * Runtime adapter for converting Storybook CSF modules to Fragment definitions.\n *\n * This operates on IMPORTED modules at runtime, not source code parsing.\n * By leveraging Vite's module system, we get 100% accurate render functions\n * without any regex or AST parsing complexity.\n *\n * Supports Storybook 8.x with both CSF2 (Template.bind) and CSF3 (object stories).\n */\n\nimport { createElement, type ComponentType, type ReactNode } from \"react\";\nimport { toId, storyNameFromExport, isExportStory } from \"./storybook-csf.js\";\nimport type {\n FragmentDefinition,\n FragmentMeta,\n FragmentUsage,\n PropDefinition,\n FragmentVariant,\n ControlType,\n VariantLoader,\n PlayFunction,\n PlayFunctionContext,\n VariantRenderOptions,\n} from \"./types.js\";\n\n// Re-export @storybook/csf utilities for use in other modules\nexport { toId, storyNameFromExport, isExportStory };\n\n/**\n * Storybook decorator function signature\n */\nexport type Decorator = (\n Story: () => ReactNode,\n context: StoryContext\n) => ReactNode;\n\n/**\n * Storybook loader function signature\n */\nexport type Loader = (context: StoryContext) => Promise<Record<string, unknown>>;\n\n/**\n * Storybook play function signature (internal, extends StoryContext)\n */\ntype StorybookPlayFunction = (context: StorybookPlayFunctionContext) => Promise<void>;\n\n/**\n * Context passed to Storybook play functions (extends StoryContext for compatibility)\n */\ninterface StorybookPlayFunctionContext extends StoryContext {\n canvasElement: HTMLElement;\n step: (name: string, fn: () => Promise<void>) => Promise<void>;\n}\n\n/**\n * Context passed to decorators and render functions\n */\nexport interface StoryContext {\n args: Record<string, unknown>;\n argTypes: Record<string, StoryArgType>;\n globals: Record<string, unknown>;\n parameters: Record<string, unknown>;\n id: string;\n kind: string;\n name: string;\n story: string;\n viewMode: \"story\" | \"docs\";\n loaded: Record<string, unknown>;\n abortSignal: AbortSignal;\n componentId: string;\n title: string;\n}\n\n/**\n * Storybook Meta (default export)\n */\nexport interface StoryMeta {\n title?: string;\n component?: ComponentType<unknown>;\n subcomponents?: Record<string, ComponentType<unknown>>;\n tags?: string[];\n parameters?: Record<string, unknown> & {\n docs?: {\n description?: {\n component?: string;\n };\n };\n };\n argTypes?: Record<string, StoryArgType>;\n args?: Record<string, unknown>;\n decorators?: Decorator[];\n loaders?: Loader[];\n render?: (args: Record<string, unknown>, context?: StoryContext) => ReactNode;\n // Story filtering\n includeStories?: string[] | RegExp;\n excludeStories?: string[] | RegExp;\n}\n\n/**\n * Storybook argType definition\n */\nexport interface StoryArgType {\n control?:\n | string\n | false\n | { type: string; min?: number; max?: number; step?: number; presetColors?: string[] };\n options?: string[];\n description?: string;\n table?: {\n defaultValue?: { summary: string };\n type?: { summary: string };\n category?: string;\n subcategory?: string;\n disable?: boolean;\n };\n type?: { name: string; required?: boolean };\n name?: string;\n defaultValue?: unknown;\n if?: { arg?: string; exists?: boolean };\n mapping?: Record<string, unknown>;\n action?: string;\n}\n\n/**\n * Storybook Story export (CSF3)\n */\nexport interface Story {\n args?: Record<string, unknown>;\n argTypes?: Record<string, StoryArgType>;\n render?: (args: Record<string, unknown>, context?: StoryContext) => ReactNode;\n decorators?: Decorator[];\n loaders?: Loader[];\n play?: StorybookPlayFunction;\n parameters?: Record<string, unknown> & {\n docs?: {\n description?: {\n story?: string;\n };\n };\n };\n name?: string;\n storyName?: string; // Legacy CSF2\n tags?: string[];\n}\n\n/**\n * CSF2 story function (from Template.bind({})) with args attached\n */\nexport type CSF2Story = ((args: Record<string, unknown>) => ReactNode) & {\n args?: Record<string, unknown>;\n argTypes?: Record<string, StoryArgType>;\n decorators?: Decorator[];\n loaders?: Loader[];\n play?: StorybookPlayFunction;\n parameters?: Record<string, unknown>;\n storyName?: string;\n};\n\n/**\n * A complete Storybook module with default meta and named story exports\n */\nexport interface StoryModule {\n default: StoryMeta;\n [exportName: string]: Story | CSF2Story | StoryMeta | unknown;\n}\n\n/**\n * Global configuration from preview.tsx\n */\nexport interface PreviewConfig {\n decorators?: Decorator[];\n parameters?: Record<string, unknown>;\n globalTypes?: Record<string, unknown>;\n args?: Record<string, unknown>;\n argTypes?: Record<string, StoryArgType>;\n loaders?: Loader[];\n}\n\n// Store for global preview config (set by previewLoader)\nlet globalPreviewConfig: PreviewConfig = {};\n\n/**\n * Set the global preview configuration loaded from .storybook/preview.tsx\n */\nexport function setPreviewConfig(config: PreviewConfig): void {\n globalPreviewConfig = config;\n}\n\n/**\n * Get the current global preview configuration\n */\nexport function getPreviewConfig(): PreviewConfig {\n return globalPreviewConfig;\n}\n\n/**\n * Convert a Storybook module to a Fragment definition at runtime.\n *\n * @param storyModule - The imported Storybook module\n * @param filePath - File path for metadata extraction\n * @returns A complete FragmentDefinition ready for the viewer\n */\nexport function storyModuleToFragment(\n storyModule: StoryModule,\n filePath: string\n): FragmentDefinition | null {\n const meta = storyModule.default;\n const component = meta.component;\n\n // Stories without a component (e.g., documentation pages, icon galleries) are skipped\n if (!component) {\n return null;\n }\n\n const componentName = extractComponentName(meta, filePath);\n const category = extractCategory(meta.title);\n const props = convertArgTypes(meta.argTypes ?? {}, globalPreviewConfig.argTypes);\n const variants = extractVariants(storyModule, component, meta);\n\n // Extract Figma URL from parameters.design.url (storybook-addon-designs) or parameters.figma\n const figmaUrl = extractFigmaUrl(meta.parameters);\n\n const fragmentMeta: FragmentMeta = {\n name: componentName,\n description:\n meta.parameters?.docs?.description?.component ??\n `${componentName} component`,\n category,\n tags: meta.tags?.filter((t) => t !== \"autodocs\"),\n status: \"stable\",\n figma: figmaUrl,\n };\n\n const usage: FragmentUsage = {\n when: [`Use ${componentName} for its intended purpose`],\n whenNot: [\"When a more specific component is available\"],\n };\n\n return {\n component,\n meta: fragmentMeta,\n usage,\n props,\n variants,\n };\n}\n\n/**\n * Extract component name from meta or file path\n */\nfunction extractComponentName(meta: StoryMeta, filePath: string): string {\n // Try title (last fragment of path like \"Components/Forms/Button\" -> \"Button\")\n if (meta.title) {\n const parts = meta.title.split(\"/\");\n return parts[parts.length - 1];\n }\n\n // Try component displayName\n if (meta.component?.displayName) {\n return meta.component.displayName;\n }\n\n // Try component name\n if (meta.component?.name && meta.component.name !== \"Component\") {\n return meta.component.name;\n }\n\n // Fallback: extract from file path\n const match = filePath.match(/([^/\\\\]+)\\.stories\\.(tsx?|jsx?)$/);\n return match?.[1] ?? \"Unknown\";\n}\n\n/**\n * Extract category from Storybook title path\n */\nfunction extractCategory(title?: string): string {\n if (!title) return \"general\";\n\n const parts = title.split(\"/\");\n // \"Components/Forms/Button\" -> \"forms\" (need at least 3 parts for a subcategory)\n if (parts.length >= 3) {\n return parts[parts.length - 2].toLowerCase();\n }\n // \"Components/Button\" -> \"general\" (no subcategory specified)\n return \"general\";\n}\n\n/**\n * Extract Figma URL from Storybook parameters\n * Supports storybook-addon-designs format and custom figma parameter\n */\nfunction extractFigmaUrl(parameters?: Record<string, unknown>): string | undefined {\n if (!parameters) return undefined;\n\n // Try storybook-addon-designs format: parameters.design.url\n const design = parameters.design as { url?: string; type?: string } | undefined;\n if (design?.url && typeof design.url === \"string\") {\n return design.url;\n }\n\n // Try custom figma parameter: parameters.figma\n if (typeof parameters.figma === \"string\") {\n return parameters.figma;\n }\n\n return undefined;\n}\n\n/**\n * Convert Storybook argTypes to Fragment props\n * Merges global argTypes from preview config with meta argTypes\n */\nfunction convertArgTypes(\n argTypes: Record<string, StoryArgType>,\n globalArgTypes?: Record<string, StoryArgType>\n): Record<string, PropDefinition> {\n const props: Record<string, PropDefinition> = {};\n\n // Merge global and meta argTypes (meta takes precedence)\n const mergedArgTypes = { ...globalArgTypes, ...argTypes };\n\n for (const [name, argType] of Object.entries(mergedArgTypes)) {\n // Skip disabled argTypes\n if (argType.table?.disable) continue;\n // Skip action-only argTypes (no control)\n if (argType.control === false && argType.action) continue;\n\n // Extract control type and options\n const { controlType, controlOptions } = extractControlInfo(argType);\n\n props[name] = {\n type: inferPropType(argType),\n description: argType.description ?? `${name} prop`,\n ...(argType.options && { values: argType.options }),\n ...(argType.table?.defaultValue && {\n default: argType.table.defaultValue.summary,\n }),\n ...(argType.defaultValue !== undefined && {\n default: argType.defaultValue,\n }),\n ...(argType.type?.required && { required: true }),\n ...(controlType && { controlType }),\n ...(controlOptions && Object.keys(controlOptions).length > 0 && { controlOptions }),\n };\n }\n\n return props;\n}\n\n/**\n * Extract control type and options from a Storybook argType\n */\nfunction extractControlInfo(argType: StoryArgType): {\n controlType?: ControlType;\n controlOptions?: PropDefinition[\"controlOptions\"];\n} {\n // Handle no control or explicitly disabled control\n if (argType.control === undefined || argType.control === false) {\n return {};\n }\n\n const control = typeof argType.control === \"string\"\n ? { type: argType.control }\n : argType.control;\n\n // Map control type string to ControlType\n const validControlTypes: ControlType[] = [\n \"text\", \"number\", \"range\", \"boolean\", \"select\", \"multi-select\",\n \"radio\", \"inline-radio\", \"check\", \"inline-check\", \"object\", \"file\", \"color\", \"date\"\n ];\n\n const controlType = validControlTypes.includes(control.type as ControlType)\n ? (control.type as ControlType)\n : undefined;\n\n // Extract control options for controls that need them\n const controlOptions: PropDefinition[\"controlOptions\"] = {};\n\n if (control.min !== undefined) controlOptions.min = control.min;\n if (control.max !== undefined) controlOptions.max = control.max;\n if (control.step !== undefined) controlOptions.step = control.step;\n if (control.presetColors) controlOptions.presetColors = control.presetColors;\n\n return {\n controlType,\n controlOptions: Object.keys(controlOptions).length > 0 ? controlOptions : undefined,\n };\n}\n\n/**\n * Infer prop type from Storybook control/type\n * Handles all Storybook 8.x control types\n */\nfunction inferPropType(argType: StoryArgType): PropDefinition[\"type\"] {\n // Action argType → function\n if (argType.action) return \"function\";\n\n // If has options, it's an enum\n if (argType.options?.length) return \"enum\";\n\n // Check explicit type\n if (argType.type?.name) {\n const typeMap: Record<string, PropDefinition[\"type\"]> = {\n string: \"string\",\n number: \"number\",\n boolean: \"boolean\",\n object: \"object\",\n array: \"array\",\n function: \"function\",\n };\n const mapped = typeMap[argType.type.name];\n if (mapped) return mapped;\n }\n\n // Check control type\n const control =\n typeof argType.control === \"string\"\n ? argType.control\n : argType.control\n ? argType.control.type\n : undefined;\n\n if (control) {\n const controlMap: Record<string, PropDefinition[\"type\"]> = {\n // Text controls\n text: \"string\",\n\n // Number controls\n number: \"number\",\n range: \"number\",\n\n // Boolean controls\n boolean: \"boolean\",\n check: \"boolean\",\n \"inline-check\": \"boolean\",\n\n // Enum/selection controls\n select: \"enum\",\n \"multi-select\": \"enum\",\n radio: \"enum\",\n \"inline-radio\": \"enum\",\n\n // Object controls\n object: \"object\",\n file: \"object\",\n\n // Special string controls\n color: \"string\",\n date: \"string\",\n };\n const mapped = controlMap[control];\n if (mapped) return mapped;\n }\n\n return \"string\";\n}\n\n/**\n * Check if a value looks like a Storybook story\n * Handles both CSF 3 (objects) and CSF 2 (functions from Template.bind({}))\n */\nfunction isStory(value: unknown): value is Story | CSF2Story {\n // CSF 3: Story is an object with args/render/play\n if (typeof value === \"object\" && value !== null) {\n const obj = value as Record<string, unknown>;\n if (\"args\" in obj || \"render\" in obj || \"play\" in obj) return true;\n }\n\n // CSF 2: Story is a function (from Template.bind({})) with args attached\n if (typeof value === \"function\") {\n const fn = value as ((...args: unknown[]) => unknown) & { args?: unknown };\n if (\"args\" in fn) return true;\n }\n\n return false;\n}\n\n/**\n * Extract variants from story exports using @storybook/csf utilities\n */\nfunction extractVariants(\n storyModule: StoryModule,\n component: ComponentType<unknown>,\n meta: StoryMeta\n): FragmentVariant[] {\n const variants: FragmentVariant[] = [];\n\n for (const [exportName, exportValue] of Object.entries(storyModule)) {\n // Skip default export\n if (exportName === \"default\") continue;\n\n // Use isExportStory to filter based on includeStories/excludeStories\n if (!isExportStory(exportName, meta)) continue;\n\n // Check if it's a story\n if (!isStory(exportValue)) continue;\n\n const story = exportValue as Story | CSF2Story;\n\n // Get story name using storyNameFromExport\n const storyName =\n (typeof story === \"object\" && story.name) ||\n (typeof story === \"object\" && story.storyName) ||\n (typeof story === \"function\" && story.storyName) ||\n storyNameFromExport(exportName);\n\n // Generate story ID matching Storybook format\n const storyId = toId(meta.title || \"Unknown\", exportName);\n\n // Extract description based on story format\n let description = `${storyName} variant`;\n if (typeof story === \"object\" && story.parameters?.docs?.description?.story) {\n description = story.parameters.docs.description.story;\n }\n\n // Check for play function and capture it\n const storyPlayFn = typeof story === \"object\" ? story.play : story.play;\n const hasPlayFunction = !!storyPlayFn;\n\n // Create wrapped play function that adapts Storybook context to our PlayFunctionContext\n const wrappedPlay: PlayFunction | undefined = storyPlayFn\n ? async (context: PlayFunctionContext): Promise<void> => {\n // Build full Storybook context for compatibility\n const args = {\n ...globalPreviewConfig.args,\n ...meta.args,\n ...(typeof story === \"function\" ? story.args : story.args),\n };\n const fullContext = buildStoryContext(meta, story, args, storyId, storyName);\n\n // Merge our context with Storybook context\n const playContext = {\n ...fullContext,\n canvasElement: context.canvasElement,\n args: context.args,\n step: context.step,\n };\n\n await storyPlayFn(playContext as unknown as StorybookPlayFunctionContext);\n }\n : undefined;\n\n // Get story tags\n const storyTags = typeof story === \"object\" ? story.tags : undefined;\n\n // Collect loaders from global, meta, and story (in order)\n const loaders = collectLoaders(meta, story);\n\n // Compute the merged args for this variant (for code generation)\n const variantArgs = {\n ...globalPreviewConfig.args,\n ...meta.args,\n ...(typeof story === \"function\" ? story.args : story.args),\n };\n\n // Only include args if there are any defined\n const hasArgs = Object.keys(variantArgs).length > 0;\n\n variants.push({\n name: storyName,\n description,\n render: createRenderFunction(story, component, meta, storyId, storyName),\n // Store Storybook-specific metadata\n ...(hasPlayFunction && { hasPlayFunction: true }),\n ...(wrappedPlay && { play: wrappedPlay }),\n ...(storyId && { storyId }),\n ...(storyTags && { tags: storyTags }),\n ...(loaders.length > 0 && { loaders }),\n ...(hasArgs && { args: variantArgs }),\n });\n }\n\n return variants;\n}\n\n/**\n * Collect loaders from global, meta, and story levels\n * Returns wrapped loader functions that execute with context\n */\nfunction collectLoaders(\n meta: StoryMeta,\n story: Story | CSF2Story\n): VariantLoader[] {\n const allLoaders: Loader[] = [\n ...(globalPreviewConfig.loaders ?? []),\n ...(meta.loaders ?? []),\n ...(typeof story === \"function\" ? story.loaders ?? [] : story.loaders ?? []),\n ];\n\n if (allLoaders.length === 0) {\n return [];\n }\n\n // Wrap each loader to execute without requiring context at call time\n // The actual context will be built when the loader is executed\n return allLoaders.map((loader) => {\n return async (): Promise<Record<string, unknown>> => {\n // Create a minimal context for loader execution\n const minimalContext: StoryContext = {\n args: {},\n argTypes: {},\n globals: {},\n parameters: {},\n id: \"\",\n kind: meta.title || \"Unknown\",\n name: \"\",\n story: \"\",\n viewMode: \"story\",\n loaded: {},\n abortSignal: new AbortController().signal,\n componentId: \"\",\n title: meta.title || \"Unknown\",\n };\n return loader(minimalContext);\n };\n });\n}\n\n/**\n * Build a StoryContext for decorators and render functions\n */\nfunction buildStoryContext(\n meta: StoryMeta,\n story: Story | CSF2Story,\n args: Record<string, unknown>,\n storyId: string,\n storyName: string,\n loadedData?: Record<string, unknown>\n): StoryContext {\n const mergedArgs = {\n ...globalPreviewConfig.args,\n ...meta.args,\n ...(typeof story === \"object\" ? story.args : story.args),\n ...args,\n };\n\n const mergedArgTypes = {\n ...globalPreviewConfig.argTypes,\n ...meta.argTypes,\n ...(typeof story === \"object\" ? story.argTypes : story.argTypes),\n };\n\n const mergedParameters = {\n ...globalPreviewConfig.parameters,\n ...meta.parameters,\n ...(typeof story === \"object\" ? story.parameters : story.parameters),\n };\n\n return {\n args: mergedArgs,\n argTypes: mergedArgTypes ?? {},\n globals: {},\n parameters: mergedParameters ?? {},\n id: storyId,\n kind: meta.title || \"Unknown\",\n name: storyName,\n story: storyName,\n viewMode: \"story\",\n loaded: loadedData ?? {},\n abortSignal: new AbortController().signal,\n componentId: toId(meta.title || \"Unknown\", \"\"),\n title: meta.title || \"Unknown\",\n };\n}\n\n/**\n * Create a render function for a story\n * Handles both CSF 3 (objects) and CSF 2 (functions)\n * Applies decorators in correct order: story → meta → global (innermost first)\n * Accepts optional args overrides and loaded data from loaders\n */\nfunction createRenderFunction(\n story: Story | CSF2Story,\n component: ComponentType<unknown>,\n meta: StoryMeta,\n storyId: string,\n storyName: string\n): (options?: VariantRenderOptions) => ReactNode {\n return (options?: VariantRenderOptions) => {\n // Merge args: global → meta → story → runtime overrides\n const args = {\n ...globalPreviewConfig.args,\n ...meta.args,\n ...(typeof story === \"function\" ? story.args : story.args),\n ...options?.args, // Runtime overrides from viewer props panel\n };\n\n const loadedData = options?.loadedData;\n\n // Build the story context with loaded data\n const context = buildStoryContext(meta, story, args, storyId, storyName, loadedData);\n\n // Create the base render function\n let renderFn: () => ReactNode;\n\n if (typeof story === \"function\") {\n // CSF 2: Story is a function (from Template.bind({}))\n renderFn = () => story(args);\n } else if (story.render) {\n // CSF 3: Story has custom render function\n // Support both render(args) and render(args, context) signatures\n renderFn = () =>\n story.render!.length >= 2\n ? story.render!(args, context)\n : story.render!(args);\n } else if (meta.render) {\n // CSF 3: Meta has default render function\n renderFn = () =>\n meta.render!.length >= 2\n ? meta.render!(args, context)\n : meta.render!(args);\n } else {\n // Default: render component with args\n renderFn = () => createElement(component, args);\n }\n\n // Collect decorators in Storybook order\n // story → meta → global, then reverse to apply innermost first\n const allDecorators = [\n ...(globalPreviewConfig.decorators ?? []),\n ...(meta.decorators ?? []),\n ...(typeof story === \"function\" ? story.decorators ?? [] : story.decorators ?? []),\n ].reverse();\n\n // Apply decorators if any\n if (allDecorators.length > 0) {\n return applyDecorators(renderFn, allDecorators, context);\n }\n\n return renderFn();\n };\n}\n\n/**\n * Apply decorators in the correct order\n * Decorators wrap from innermost to outermost\n */\nfunction applyDecorators(\n renderFn: () => ReactNode,\n decorators: Decorator[],\n context: StoryContext\n): ReactNode {\n // Start with the base render function\n let storyFn: () => ReactNode = renderFn;\n\n // Each decorator wraps the previous one\n for (const decorator of decorators) {\n const wrappedFn = storyFn;\n storyFn = () => decorator(wrappedFn, context);\n }\n\n return storyFn();\n}\n\n/**\n * Convert PascalCase to Title Case\n * @deprecated Use storyNameFromExport from @storybook/csf instead\n */\nfunction pascalToTitle(name: string): string {\n return name.replace(/([A-Z])/g, \" $1\").trim();\n}\n","import {\n toId as storybookToId,\n storyNameFromExport as storybookStoryNameFromExport,\n isExportStory as storybookIsExportStory,\n} from \"@storybook/csf\";\n\nexport const toId: typeof storybookToId = (...args) => storybookToId(...args);\nexport const storyNameFromExport: typeof storybookStoryNameFromExport = (...args) =>\n storybookStoryNameFromExport(...args);\nexport const isExportStory: typeof storybookIsExportStory = (...args) =>\n storybookIsExportStory(...args);\n","/**\n * Smart filtering for Storybook adapter.\n *\n * Two layers:\n * 1. Per-file heuristics — checkStoryExclusion() checks title, tags, component name, etc.\n * 2. Cross-file sub-component detection — detectSubComponentPaths() uses directory structure.\n *\n * All functions are pure (no I/O, no side effects) for easy testing.\n */\n\nimport type { StorybookFilterConfig } from './types.js';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport type ExclusionReason =\n | 'deprecated' // title contains \"Deprecated\"\n | 'test-story' // title ends /tests? OR file matches *.test.stories.*\n | 'svg-icon' // component name starts with Svg[A-Z]\n | 'tag-excluded' // meta.tags includes hidden/internal/no-fragment\n | 'empty-variants' // zero renderable story exports\n | 'sub-component' // directory-based: file in another component's folder\n | 'config-excluded'; // user explicit exclude pattern\n\nexport interface ExclusionResult {\n excluded: boolean;\n reason?: ExclusionReason;\n detail?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Per-file heuristics\n// ---------------------------------------------------------------------------\n\nconst EXCLUDED_TAGS = new Set(['hidden', 'internal', 'no-fragment']);\n\nconst SVG_ICON_RE = /^Svg[A-Z]/;\nconst TEST_TITLE_RE = /\\/tests?$/i;\nconst TEST_FILE_RE = /\\.test\\.stories\\./;\nconst DEPRECATED_TITLE_RE = /\\bDeprecated\\b/i;\n\nexport interface CheckStoryExclusionOpts {\n storybookTitle?: string;\n componentName: string;\n componentDisplayName?: string;\n componentFunctionName?: string;\n tags?: string[];\n variantCount: number;\n filePath: string;\n config: StorybookFilterConfig;\n}\n\n/**\n * Per-file exclusion check. Returns `{ excluded: true, reason, detail }` when\n * the fragment should be filtered out, or `{ excluded: false }` when it should\n * be kept.\n *\n * Config `include` trumps everything — if a name matches `include`, it is\n * never excluded by heuristics.\n */\nexport function checkStoryExclusion(opts: CheckStoryExclusionOpts): ExclusionResult {\n const { config } = opts;\n\n // Force-included names bypass all heuristic filters\n if (isForceIncluded(opts.componentName, config)) {\n return { excluded: false };\n }\n\n // Config explicit exclude\n if (isConfigExcluded(opts.componentName, config)) {\n return {\n excluded: true,\n reason: 'config-excluded',\n detail: `'${opts.componentName}' matches storybook.exclude pattern`,\n };\n }\n\n // Deprecated\n if (config.excludeDeprecated !== false && opts.storybookTitle && DEPRECATED_TITLE_RE.test(opts.storybookTitle)) {\n return {\n excluded: true,\n reason: 'deprecated',\n detail: `Title \"${opts.storybookTitle}\" contains \"Deprecated\"`,\n };\n }\n\n // Test stories\n if (config.excludeTests !== false) {\n if (opts.storybookTitle && TEST_TITLE_RE.test(opts.storybookTitle)) {\n return {\n excluded: true,\n reason: 'test-story',\n detail: `Title \"${opts.storybookTitle}\" ends with /test(s)`,\n };\n }\n if (TEST_FILE_RE.test(opts.filePath)) {\n return {\n excluded: true,\n reason: 'test-story',\n detail: `File path matches *.test.stories.*`,\n };\n }\n }\n\n // SVG icons\n if (config.excludeSvgIcons !== false) {\n const names = [opts.componentName, opts.componentDisplayName, opts.componentFunctionName].filter(Boolean) as string[];\n for (const name of names) {\n if (SVG_ICON_RE.test(name)) {\n return {\n excluded: true,\n reason: 'svg-icon',\n detail: `Component name \"${name}\" matches Svg[A-Z] pattern`,\n };\n }\n }\n }\n\n // Excluded tags\n if (opts.tags?.length) {\n const hit = opts.tags.find(t => EXCLUDED_TAGS.has(t));\n if (hit) {\n return {\n excluded: true,\n reason: 'tag-excluded',\n detail: `Tag \"${hit}\" is in the exclusion set`,\n };\n }\n }\n\n // Empty variants\n if (opts.variantCount === 0) {\n return {\n excluded: true,\n reason: 'empty-variants',\n detail: 'Zero renderable story exports',\n };\n }\n\n return { excluded: false };\n}\n\n// ---------------------------------------------------------------------------\n// Cross-file sub-component detection\n// ---------------------------------------------------------------------------\n\n/**\n * Given all story file relative paths, detect which ones are sub-components\n * based on directory structure.\n *\n * Heuristic: within a directory, if one story file's base name matches the\n * directory name, it is the \"primary\" component. All other story files in\n * the same directory are considered sub-components.\n *\n * Example:\n * src/components/Form/Form.stories.tsx → primary (\"Form\")\n * src/components/Form/Checkbox.stories.tsx → sub-component of \"Form\"\n * src/components/Form/RadioGroup.stories.tsx → sub-component of \"Form\"\n *\n * Returns a Map from relative path → parent component name.\n * Paths NOT in the map are standalone components.\n */\nexport function detectSubComponentPaths(\n storyFiles: Array<{ relativePath: string }>\n): Map<string, string> {\n // Group story files by their parent directory\n const byDir = new Map<string, Array<{ relativePath: string; baseName: string }>>();\n\n for (const file of storyFiles) {\n const parts = file.relativePath.split('/');\n if (parts.length < 2) continue; // skip root-level files\n\n const fileName = parts[parts.length - 1];\n // Extract base name: \"Form.stories.tsx\" → \"Form\"\n const baseMatch = fileName.match(/^([^.]+)\\.stories\\./);\n if (!baseMatch) continue;\n\n const dir = parts.slice(0, -1).join('/');\n const baseName = baseMatch[1];\n\n if (!byDir.has(dir)) byDir.set(dir, []);\n byDir.get(dir)!.push({ relativePath: file.relativePath, baseName });\n }\n\n const subComponentMap = new Map<string, string>();\n\n for (const [dir, files] of byDir) {\n if (files.length <= 1) continue; // single file in dir → always standalone\n\n // Directory name is the last segment: \"src/components/Form\" → \"Form\"\n const dirName = dir.split('/').pop()!;\n\n // Find the primary: story whose base name matches the directory name\n const primary = files.find(f => f.baseName === dirName);\n if (!primary) continue; // no clear primary → keep all\n\n // All others in this dir are sub-components\n for (const file of files) {\n if (file.relativePath === primary.relativePath) continue;\n subComponentMap.set(file.relativePath, primary.baseName);\n }\n }\n\n return subComponentMap;\n}\n\n// ---------------------------------------------------------------------------\n// Config helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Check if a component name matches the `storybook.include` patterns.\n * Include is a force-include that bypasses all heuristic filters.\n */\nexport function isForceIncluded(name: string, config: StorybookFilterConfig): boolean {\n if (!config.include?.length) return false;\n return config.include.some(pattern => matchesPattern(name, pattern));\n}\n\n/**\n * Check if a component name matches the `storybook.exclude` patterns.\n */\nexport function isConfigExcluded(name: string, config: StorybookFilterConfig): boolean {\n if (!config.exclude?.length) return false;\n return config.exclude.some(pattern => matchesPattern(name, pattern));\n}\n\n/**\n * Simple pattern matching: exact match or glob-style prefix/suffix wildcards.\n * \"Button\" → exact match\n * \"Svg*\" → prefix match\n * \"*Icon\" → suffix match\n * \"*Badge*\" → contains match\n */\nfunction matchesPattern(name: string, pattern: string): boolean {\n if (!pattern.includes('*')) {\n return name === pattern;\n }\n\n const parts = pattern.split('*');\n if (parts.length === 2) {\n const [prefix, suffix] = parts;\n if (prefix && suffix) return name.startsWith(prefix) && name.endsWith(suffix);\n if (prefix) return name.startsWith(prefix);\n if (suffix) return name.endsWith(suffix);\n return true; // pattern is just \"*\"\n }\n\n // Multi-wildcard: convert to regex\n const escaped = parts.map(p => p.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('.*');\n return new RegExp(`^${escaped}$`).test(name);\n}\n","export { generateContext, filterPlaceholders, PLACEHOLDER_PATTERNS } from '@fragments-sdk/context/generate';\nexport type { ContextOptions, ContextResult } from '@fragments-sdk/context/generate';\n","/**\n * Figma property mapping DSL\n *\n * Provides helpers for mapping Figma component properties to code props.\n * Inspired by Figma Code Connect's API.\n *\n * @example\n * ```tsx\n * import { defineFragment, figma } from '@fragments-sdk/cli/core';\n *\n * export default defineFragment({\n * component: Button,\n * meta: {\n * name: 'Button',\n * description: 'Primary action trigger',\n * category: 'actions',\n * figma: 'https://figma.com/file/abc/Design?node-id=1-2',\n * figmaProps: {\n * children: figma.string('Label'),\n * disabled: figma.boolean('Disabled'),\n * variant: figma.enum('Type', {\n * 'Primary': 'primary',\n * 'Secondary': 'secondary',\n * }),\n * },\n * },\n * // ...\n * });\n * ```\n */\n\nimport type {\n FigmaStringMapping,\n FigmaBooleanMapping,\n FigmaEnumMapping,\n FigmaInstanceMapping,\n FigmaChildrenMapping,\n FigmaTextContentMapping,\n} from './types.js';\n\n/**\n * Map a Figma text property to a string prop.\n *\n * @param figmaProperty - The name of the text property in Figma\n * @returns A string mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * label: figma.string('Button Text'),\n * placeholder: figma.string('Placeholder'),\n * }\n * ```\n */\nfunction string(figmaProperty: string): FigmaStringMapping {\n return {\n __type: 'figma-string',\n figmaProperty,\n };\n}\n\n/**\n * Map a Figma boolean property to a boolean prop.\n * Optionally map true/false to different values.\n *\n * @param figmaProperty - The name of the boolean property in Figma\n * @param valueMapping - Optional mapping of true/false to other values\n * @returns A boolean mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * disabled: figma.boolean('Disabled'),\n * // Map boolean to string values\n * size: figma.boolean('Large', { true: 'lg', false: 'md' }),\n * }\n * ```\n */\nfunction boolean(\n figmaProperty: string,\n valueMapping?: { true: unknown; false: unknown }\n): FigmaBooleanMapping {\n return {\n __type: 'figma-boolean',\n figmaProperty,\n valueMapping,\n };\n}\n\n/**\n * Map a Figma variant property to an enum prop.\n *\n * @param figmaProperty - The name of the variant property in Figma\n * @param valueMapping - Mapping of Figma values to code values\n * @returns An enum mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * variant: figma.enum('Type', {\n * 'Primary': 'primary',\n * 'Secondary': 'secondary',\n * 'Outline': 'outline',\n * }),\n * size: figma.enum('Size', {\n * 'Small': 'sm',\n * 'Medium': 'md',\n * 'Large': 'lg',\n * }),\n * }\n * ```\n */\nfunction enumValue<T extends Record<string, unknown>>(\n figmaProperty: string,\n valueMapping: T\n): FigmaEnumMapping {\n return {\n __type: 'figma-enum',\n figmaProperty,\n valueMapping,\n };\n}\n\n/**\n * Reference a nested Figma component instance.\n * Use this when a prop accepts a component that's represented\n * as an instance swap in Figma.\n *\n * @param figmaProperty - The name of the instance property in Figma\n * @returns An instance mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * icon: figma.instance('Icon'),\n * avatar: figma.instance('Avatar'),\n * }\n * ```\n */\nfunction instance(figmaProperty: string): FigmaInstanceMapping {\n return {\n __type: 'figma-instance',\n figmaProperty,\n };\n}\n\n/**\n * Render children from specific Figma layers.\n * Use this when children are represented as named layers in Figma.\n *\n * @param layers - Array of layer names to include as children\n * @returns A children mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * children: figma.children(['Title', 'Description', 'Actions']),\n * }\n * ```\n */\nfunction children(layers: string[]): FigmaChildrenMapping {\n return {\n __type: 'figma-children',\n layers,\n };\n}\n\n/**\n * Extract text content from a Figma text layer.\n * Use this when a prop should be the actual text from a layer.\n *\n * @param layer - The name of the text layer in Figma\n * @returns A text content mapping descriptor\n *\n * @example\n * ```tsx\n * figmaProps: {\n * title: figma.textContent('Header Text'),\n * description: figma.textContent('Body Text'),\n * }\n * ```\n */\nfunction textContent(layer: string): FigmaTextContentMapping {\n return {\n __type: 'figma-text-content',\n layer,\n };\n}\n\n/**\n * Figma property mapping helpers.\n *\n * Use these to define how Figma properties map to your component props.\n * The mappings are used for:\n * - Generating accurate code snippets in Figma Dev Mode\n * - AI agents understanding the design-to-code relationship\n * - Automated design verification\n */\nexport const figma = {\n string,\n boolean,\n enum: enumValue,\n instance,\n children,\n textContent,\n} as const;\n\n/**\n * Helper type to check if a value is a Figma prop mapping\n */\nexport function isFigmaPropMapping(\n value: unknown\n): value is FigmaStringMapping | FigmaBooleanMapping | FigmaEnumMapping | FigmaInstanceMapping | FigmaChildrenMapping | FigmaTextContentMapping {\n if (typeof value !== 'object' || value === null || !('__type' in value)) {\n return false;\n }\n const typeValue = (value as Record<string, unknown>).__type;\n return typeof typeValue === 'string' && typeValue.startsWith('figma-');\n}\n\n/**\n * Resolve a Figma prop mapping to an actual value given Figma property values.\n *\n * @param mapping - The Figma prop mapping\n * @param figmaValues - Object containing Figma property values\n * @returns The resolved value for the code prop\n */\nexport function resolveFigmaMapping(\n mapping: FigmaStringMapping | FigmaBooleanMapping | FigmaEnumMapping | FigmaInstanceMapping | FigmaChildrenMapping | FigmaTextContentMapping,\n figmaValues: Record<string, unknown>\n): unknown {\n switch (mapping.__type) {\n case 'figma-string':\n return figmaValues[mapping.figmaProperty] ?? '';\n\n case 'figma-boolean': {\n const boolValue = figmaValues[mapping.figmaProperty] as boolean;\n if (mapping.valueMapping) {\n return boolValue ? mapping.valueMapping.true : mapping.valueMapping.false;\n }\n return boolValue;\n }\n\n case 'figma-enum': {\n const enumKey = figmaValues[mapping.figmaProperty] as string;\n return mapping.valueMapping[enumKey] ?? enumKey;\n }\n\n case 'figma-instance':\n // Instance mappings return the instance reference\n return figmaValues[mapping.figmaProperty];\n\n case 'figma-children':\n // Children mappings return array of layer contents\n return mapping.layers.map((layer) => figmaValues[layer]);\n\n case 'figma-text-content':\n return figmaValues[mapping.layer] ?? '';\n\n default:\n return undefined;\n }\n}\n","/**\n * Token Parser — extracts CSS custom property declarations from SCSS/CSS files.\n *\n * Parses files for `--prefix-*: value;` declarations and groups them\n * by SCSS comment sections (e.g., `// Typography`, `// Colors`).\n * Falls back to naming-convention-based categorization when comments\n * are absent.\n */\n\nexport interface ParsedToken {\n /** Full CSS variable name (e.g., \"--fui-color-accent\") */\n name: string;\n /** Raw value from the declaration (e.g., \"#{$fui-space-4}\" or \"16px\") */\n value?: string;\n /** Resolved value after SCSS variable substitution (e.g., \"16px\") */\n resolvedValue?: string;\n /** Category inferred from SCSS comment or naming convention */\n category: string;\n /** Description from inline comment, if any */\n description?: string;\n}\n\nexport interface TokenParseOutput {\n /** Detected prefix (e.g., \"--fui-\") */\n prefix: string;\n /** Tokens grouped by category */\n categories: Record<string, ParsedToken[]>;\n /** Total number of tokens found */\n total: number;\n}\n\n/**\n * Category inference from naming conventions.\n * Order matters — first match wins.\n */\nconst NAMING_RULES: Array<{ pattern: RegExp; category: string }> = [\n { pattern: /--\\w+-font-/, category: 'typography' },\n { pattern: /--\\w+-line-height-/, category: 'typography' },\n { pattern: /--\\w+-space-/, category: 'spacing' },\n { pattern: /--\\w+-padding-/, category: 'spacing' },\n { pattern: /--\\w+-radius-/, category: 'radius' },\n { pattern: /--\\w+-color-/, category: 'colors' },\n { pattern: /--\\w+-bg-/, category: 'surfaces' },\n { pattern: /--\\w+-text-/, category: 'text' },\n { pattern: /--\\w+-border/, category: 'borders' },\n { pattern: /--\\w+-shadow-/, category: 'shadows' },\n { pattern: /--\\w+-focus-/, category: 'focus' },\n { pattern: /--\\w+-transition-/, category: 'transitions' },\n { pattern: /--\\w+-scrollbar-/, category: 'scrollbar' },\n { pattern: /--\\w+-z-index/, category: 'z-index' },\n { pattern: /--\\w+-(button|input|touch)-/, category: 'component-sizing' },\n { pattern: /--\\w+-appshell-/, category: 'layout' },\n { pattern: /--\\w+-header-/, category: 'layout' },\n { pattern: /--\\w+-code-/, category: 'code' },\n { pattern: /--\\w+-tooltip-/, category: 'tooltip' },\n { pattern: /--\\w+-hero-/, category: 'marketing' },\n];\n\n/**\n * Infer category from a CSS variable name using naming conventions.\n */\nfunction inferCategory(name: string): string {\n for (const rule of NAMING_RULES) {\n if (rule.pattern.test(name)) {\n return rule.category;\n }\n }\n return 'other';\n}\n\n/**\n * Detect the most common prefix from a list of CSS variable names.\n * E.g., given [\"--fui-color-accent\", \"--fui-bg-primary\"] → \"--fui-\"\n */\nfunction detectPrefix(names: string[]): string {\n if (names.length === 0) return '--';\n\n // Find common prefix after \"--\"\n const stripped = names.map((n) => n.slice(2)); // remove \"--\"\n let prefix = '';\n const first = stripped[0];\n\n for (let i = 0; i < first.length; i++) {\n const ch = first[i];\n if (stripped.every((s) => s[i] === ch)) {\n prefix += ch;\n } else {\n break;\n }\n }\n\n // Trim to last hyphen to get clean prefix\n const lastHyphen = prefix.lastIndexOf('-');\n if (lastHyphen > 0) {\n prefix = prefix.slice(0, lastHyphen + 1);\n }\n\n return `--${prefix}`;\n}\n\n/**\n * Normalize a SCSS comment into a category name.\n * \"// Typography\" → \"typography\"\n * \"// Component heights\" → \"component-sizing\"\n * \"// Hero/Marketing gradient\" → \"marketing\"\n */\nfunction normalizeCategory(comment: string): string {\n const text = comment\n .trim()\n .replace(/^\\/\\/\\s*/, '')\n .replace(/^\\/\\*+\\s*/, '')\n .replace(/\\s*\\*+\\/$/, '')\n .trim()\n .toLowerCase();\n\n // Map common comment headings to clean category names\n const mappings: Record<string, string> = {\n 'base configuration': 'base',\n 'typography': 'typography',\n 'spacing (micro)': 'spacing',\n 'spacing': 'spacing',\n 'density padding': 'spacing',\n 'border radius': 'radius',\n 'transitions': 'transitions',\n 'colors': 'colors',\n 'surfaces': 'surfaces',\n 'text': 'text',\n 'borders': 'borders',\n 'shadows': 'shadows',\n 'focus': 'focus',\n 'scrollbar': 'scrollbar',\n 'component heights': 'component-sizing',\n 'appshell layout': 'layout',\n 'codeblock': 'code',\n 'tooltip': 'tooltip',\n 'hero/marketing gradient': 'marketing',\n };\n\n return mappings[text] ?? text.replace(/\\s+/g, '-');\n}\n\n/**\n * Extract SCSS variable declarations ($name: value;) from file content.\n * Returns a map of variable name → value.\n */\nfunction extractScssVariables(content: string): Map<string, string> {\n const vars = new Map<string, string>();\n // Match: $var-name: value; (handles multi-word values, stops at semicolon)\n const scssVarRegex = /^\\s*(\\$[\\w-]+)\\s*:\\s*(.+?)\\s*(?:!default\\s*)?;/gm;\n\n let match: RegExpExecArray | null;\n while ((match = scssVarRegex.exec(content)) !== null) {\n const name = match[1];\n const value = match[2].replace(/\\s*\\/\\/.*$/, '').trim();\n // Only store the first occurrence (canonical definition)\n if (!vars.has(name)) {\n vars.set(name, value);\n }\n }\n\n return vars;\n}\n\n/**\n * Resolve SCSS interpolations and variable references in a token value.\n *\n * Handles:\n * - `#{$var}` → looks up $var in scssVars map\n * - `$var` standalone → looks up in scssVars map\n * - `var(--other-token, fallback)` → returns fallback if provided\n * - Recursive resolution up to 5 levels deep\n */\nfunction resolveTokenValue(\n rawValue: string,\n scssVars: Map<string, string>,\n cssVarValues: Map<string, string>,\n depth = 0\n): string {\n if (depth > 5) return rawValue; // Prevent infinite recursion\n\n let resolved = rawValue;\n\n // Resolve #{$var} interpolations\n resolved = resolved.replace(/#\\{(\\$[\\w-]+)\\}/g, (_, varName) => {\n const val = scssVars.get(varName);\n return val !== undefined\n ? resolveTokenValue(val, scssVars, cssVarValues, depth + 1)\n : `#{${varName}}`;\n });\n\n // Resolve standalone $var references (not inside #{})\n resolved = resolved.replace(/(?<![#\\{])(\\$[\\w-]+)/g, (_, varName) => {\n const val = scssVars.get(varName);\n return val !== undefined\n ? resolveTokenValue(val, scssVars, cssVarValues, depth + 1)\n : varName;\n });\n\n // Resolve var(--token, fallback) — use the referenced token value or fallback\n resolved = resolved.replace(\n /var\\((--[\\w-]+)(?:\\s*,\\s*(.+?))?\\)/g,\n (original, tokenName, fallback) => {\n const tokenVal = cssVarValues.get(tokenName);\n if (tokenVal !== undefined) {\n return resolveTokenValue(tokenVal, scssVars, cssVarValues, depth + 1);\n }\n if (fallback) {\n return resolveTokenValue(fallback.trim(), scssVars, cssVarValues, depth + 1);\n }\n return original;\n }\n );\n\n return resolved;\n}\n\n/**\n * Parse a SCSS or CSS file and extract CSS custom property declarations.\n *\n * Handles two grouping strategies:\n * 1. Comment-based: Uses `// Category` comments above groups of declarations\n * 2. Naming-based: Falls back to inferring category from variable name patterns\n *\n * Also resolves SCSS variable interpolations (e.g., `#{$fui-space-4}` → `16px`)\n * when the SCSS variable definitions are found in the same file content.\n */\nexport function parseTokenFile(content: string, filePath: string): TokenParseOutput {\n const lines = content.split('\\n');\n const tokens: ParsedToken[] = [];\n const seenNames = new Set<string>();\n let currentCategory = 'other';\n let hasCommentCategories = false;\n\n // First pass: extract SCSS variable declarations for resolution\n const scssVars = extractScssVariables(content);\n\n // Regex for CSS custom property declarations\n // Matches: --name: value; (with optional SCSS interpolation)\n // Captures both the variable name and its value\n const varDeclRegex = /^\\s*(--[\\w-]+)\\s*:\\s*(.+?)\\s*;/;\n // Regex for section comments (// Category or /* Category */)\n // Allow any characters after uppercase start (including / for \"Hero/Marketing\")\n const sectionCommentRegex = /^\\s*\\/\\/\\s+([A-Z].+)$/;\n\n for (const line of lines) {\n // Check for section comment\n const commentMatch = line.match(sectionCommentRegex);\n if (commentMatch) {\n const normalized = normalizeCategory(commentMatch[0]);\n if (normalized) {\n currentCategory = normalized;\n hasCommentCategories = true;\n }\n continue;\n }\n\n // Check for CSS variable declaration\n const varMatch = line.match(varDeclRegex);\n if (varMatch) {\n const name = varMatch[1];\n const rawValue = varMatch[2];\n\n // Deduplicate: keep only the first occurrence of each variable.\n // Dark mode and high contrast blocks redefine the same variables\n // with different values — we only want the canonical list.\n if (seenNames.has(name)) continue;\n seenNames.add(name);\n\n // Extract inline comment if present\n const inlineComment = line.match(/\\/\\/\\s*(.+)$/);\n const description = inlineComment ? inlineComment[1].trim() : undefined;\n\n // Clean the value: strip trailing inline comments\n const cleanValue = rawValue.replace(/\\s*\\/\\/.*$/, '').trim();\n\n tokens.push({\n name,\n value: cleanValue || undefined,\n category: hasCommentCategories ? currentCategory : inferCategory(name),\n description,\n });\n }\n }\n\n // Second pass: build a CSS custom property → raw value map for cross-references\n const cssVarValues = new Map<string, string>();\n for (const token of tokens) {\n if (token.value) {\n cssVarValues.set(token.name, token.value);\n }\n }\n\n // Third pass: resolve SCSS interpolations and var() references\n for (const token of tokens) {\n if (token.value) {\n const resolved = resolveTokenValue(token.value, scssVars, cssVarValues);\n // Only set resolvedValue if it's different from raw and doesn't still contain unresolved refs\n if (resolved !== token.value && !resolved.includes('#{') && !resolved.includes('$')) {\n token.resolvedValue = resolved;\n }\n }\n }\n\n // Group by category\n const categories: Record<string, ParsedToken[]> = {};\n for (const token of tokens) {\n if (!categories[token.category]) {\n categories[token.category] = [];\n }\n categories[token.category].push(token);\n }\n\n // Detect prefix\n const prefix = detectPrefix(tokens.map((t) => t.name));\n\n return {\n prefix,\n categories,\n total: tokens.length,\n };\n}\n","import type { CompiledFragment, RelationshipType } from \"./types.js\";\nimport type { ComponentGraph } from \"@fragments-sdk/context/graph\";\nimport { ComponentGraphEngine } from \"@fragments-sdk/context/graph\";\n\n// --- Public types ---\n\nexport interface CompositionWarning {\n type:\n | \"missing_parent\"\n | \"missing_child\"\n | \"missing_composition\"\n | \"redundant_alternative\"\n | \"deprecated\"\n | \"experimental\";\n component: string;\n message: string;\n relatedComponent?: string;\n}\n\nexport interface CompositionSuggestion {\n component: string;\n reason: string;\n relationship: RelationshipType | \"category_gap\";\n sourceComponent: string;\n}\n\nexport interface CompositionGuideline {\n component: string;\n guideline: string;\n}\n\nexport interface CompositionAnalysis {\n /** The validated component names (filtered to those that exist) */\n components: string[];\n\n /** Components requested but not found in the registry */\n unknown: string[];\n\n /** Issues with the current selection */\n warnings: CompositionWarning[];\n\n /** Components to consider adding */\n suggestions: CompositionSuggestion[];\n\n /** Relevant usage guidelines for the selected components */\n guidelines: CompositionGuideline[];\n}\n\n// --- Category affinities ---\n\nconst CATEGORY_AFFINITIES: Record<string, string[]> = {\n forms: [\"feedback\"],\n actions: [\"feedback\"],\n};\n\n// --- Main function ---\n\n/**\n * Analyzes a set of components as a composition group.\n * Returns warnings about missing relations, usage conflicts,\n * and suggestions for additional components.\n *\n * When a ComponentGraph is provided via `options.graph`, the analysis is\n * enhanced with graph-based dependency detection and block-based suggestions.\n *\n * Browser-safe: no Node.js APIs used.\n */\nexport function analyzeComposition(\n fragments: Record<string, CompiledFragment>,\n componentNames: string[],\n _context?: string,\n options?: { graph?: ComponentGraph },\n): CompositionAnalysis {\n const allNames = new Set(Object.keys(fragments));\n\n // 1. Validate names\n const components: string[] = [];\n const unknown: string[] = [];\n for (const name of componentNames) {\n if (allNames.has(name)) {\n components.push(name);\n } else {\n unknown.push(name);\n }\n }\n\n const selectedSet = new Set(components);\n const warnings: CompositionWarning[] = [];\n const suggestions: CompositionSuggestion[] = [];\n const guidelines: CompositionGuideline[] = [];\n\n // Track suggestions to avoid duplicates\n const suggestedSet = new Set<string>();\n\n for (const name of components) {\n const fragment = fragments[name];\n\n // 2. Relation checks\n if (fragment.relations) {\n for (const rel of fragment.relations) {\n switch (rel.relationship) {\n case \"parent\":\n if (!selectedSet.has(rel.component)) {\n warnings.push({\n type: \"missing_parent\",\n component: name,\n message: `\"${name}\" expects to be wrapped by \"${rel.component}\"${rel.note ? `: ${rel.note}` : \"\"}`,\n relatedComponent: rel.component,\n });\n }\n break;\n\n case \"child\":\n if (!selectedSet.has(rel.component) && !suggestedSet.has(rel.component)) {\n suggestions.push({\n component: rel.component,\n reason: `\"${name}\" typically contains \"${rel.component}\"${rel.note ? `: ${rel.note}` : \"\"}`,\n relationship: \"child\",\n sourceComponent: name,\n });\n suggestedSet.add(rel.component);\n }\n break;\n\n case \"composition\":\n if (!selectedSet.has(rel.component)) {\n warnings.push({\n type: \"missing_composition\",\n component: name,\n message: `\"${name}\" is typically used together with \"${rel.component}\"${rel.note ? `: ${rel.note}` : \"\"}`,\n relatedComponent: rel.component,\n });\n }\n break;\n\n case \"sibling\":\n if (!selectedSet.has(rel.component) && !suggestedSet.has(rel.component)) {\n suggestions.push({\n component: rel.component,\n reason: `\"${rel.component}\" is a sibling of \"${name}\"${rel.note ? `: ${rel.note}` : \"\"}`,\n relationship: \"sibling\",\n sourceComponent: name,\n });\n suggestedSet.add(rel.component);\n }\n break;\n\n case \"alternative\":\n if (selectedSet.has(rel.component)) {\n warnings.push({\n type: \"redundant_alternative\",\n component: name,\n message: `\"${name}\" and \"${rel.component}\" are alternatives — using both may be redundant${rel.note ? `: ${rel.note}` : \"\"}`,\n relatedComponent: rel.component,\n });\n }\n break;\n }\n }\n }\n\n // 3. Usage conflict checks (whenNot)\n if (fragment.usage?.whenNot) {\n for (const whenNotEntry of fragment.usage.whenNot) {\n const lower = whenNotEntry.toLowerCase();\n for (const other of components) {\n if (other !== name && lower.includes(other.toLowerCase())) {\n guidelines.push({\n component: name,\n guideline: `Potential conflict with \"${other}\": ${whenNotEntry}`,\n });\n }\n }\n }\n }\n\n // 4. Status warnings\n if (fragment.meta.status === \"deprecated\") {\n warnings.push({\n type: \"deprecated\",\n component: name,\n message: fragment.meta.description\n ? `\"${name}\" is deprecated: ${fragment.meta.description}`\n : `\"${name}\" is deprecated`,\n });\n } else if (fragment.meta.status === \"experimental\") {\n warnings.push({\n type: \"experimental\",\n component: name,\n message: `\"${name}\" is experimental and may change without notice`,\n });\n }\n }\n\n // 5. Category gap analysis\n const selectedCategories = new Set(\n components.map((name) => fragments[name].meta.category)\n );\n\n for (const [category, affinities] of Object.entries(CATEGORY_AFFINITIES)) {\n if (!selectedCategories.has(category)) continue;\n\n for (const neededCategory of affinities) {\n if (selectedCategories.has(neededCategory)) continue;\n\n // Find the best component from the needed category\n const candidate = findBestCategoryCandidate(\n fragments,\n neededCategory,\n selectedSet,\n suggestedSet\n );\n if (candidate) {\n suggestions.push({\n component: candidate,\n reason: `Compositions using \"${category}\" components often benefit from a \"${neededCategory}\" component`,\n relationship: \"category_gap\",\n sourceComponent: components.find(\n (n) => fragments[n].meta.category === category\n )!,\n });\n suggestedSet.add(candidate);\n }\n }\n }\n\n // 6. Graph-enhanced analysis (when graph data is available)\n if (options?.graph) {\n const engine = new ComponentGraphEngine(options.graph);\n\n // Add graph-based dependency warnings\n for (const name of components) {\n const deps = engine.dependencies(name, [\"imports\", \"hook-depends\"]);\n for (const dep of deps) {\n if (\n !selectedSet.has(dep.target) &&\n !suggestedSet.has(dep.target) &&\n allNames.has(dep.target)\n ) {\n suggestions.push({\n component: dep.target,\n reason: `\"${name}\" ${dep.type === \"hook-depends\" ? \"uses a hook from\" : \"imports\"} \"${dep.target}\"`,\n relationship: \"composition\",\n sourceComponent: name,\n });\n suggestedSet.add(dep.target);\n }\n }\n }\n\n // Add block-based suggestions\n for (const name of components) {\n const blocks = engine.blocksUsing(name);\n for (const blockName of blocks) {\n // Find other components in this block that aren't selected\n const blockComps = options.graph.edges\n .filter(\n (e) =>\n e.type === \"composes\" &&\n e.provenance === `block:${blockName}` &&\n (e.source === name || e.target === name)\n )\n .map((e) => (e.source === name ? e.target : e.source));\n\n for (const comp of blockComps) {\n if (\n !selectedSet.has(comp) &&\n !suggestedSet.has(comp) &&\n allNames.has(comp)\n ) {\n suggestions.push({\n component: comp,\n reason: `\"${name}\" and \"${comp}\" are used together in the \"${blockName}\" block`,\n relationship: \"composition\",\n sourceComponent: name,\n });\n suggestedSet.add(comp);\n }\n }\n }\n }\n }\n\n return { components, unknown, warnings, suggestions, guidelines };\n}\n\n/**\n * Find the best candidate component from a given category.\n * Prefers stable components and avoids already-selected or already-suggested ones.\n */\nfunction findBestCategoryCandidate(\n fragments: Record<string, CompiledFragment>,\n category: string,\n selectedSet: Set<string>,\n suggestedSet: Set<string>\n): string | null {\n let best: string | null = null;\n let bestScore = -1;\n\n for (const [name, fragment] of Object.entries(fragments)) {\n if (fragment.meta.category !== category) continue;\n if (selectedSet.has(name) || suggestedSet.has(name)) continue;\n\n const status = fragment.meta.status ?? \"stable\";\n let score = 0;\n if (status === \"stable\") score = 3;\n else if (status === \"beta\") score = 2;\n else if (status === \"experimental\") score = 1;\n // deprecated gets 0\n\n if (score > bestScore) {\n bestScore = score;\n best = name;\n }\n }\n\n return best;\n}\n","import { useEffect, useState, type ReactNode } from \"react\";\nimport type { VariantLoader, VariantRenderOptions } from \"./types.js\";\n\n/**\n * Minimal contract for rendering a preview variant.\n * Compatible with fragment variants and Storybook-adapted variants.\n */\nexport interface PreviewVariantLike {\n render: (options?: VariantRenderOptions) => ReactNode;\n loaders?: VariantLoader[];\n}\n\nexport interface PreviewRuntimeState {\n content: ReactNode | null;\n isLoading: boolean;\n error: Error | null;\n loadedData?: Record<string, unknown>;\n}\n\nexport interface PreviewRuntimeOptions {\n variant?: PreviewVariantLike | null;\n loadedData?: Record<string, unknown>;\n}\n\nconst EMPTY_STATE: PreviewRuntimeState = {\n content: null,\n isLoading: false,\n error: null,\n loadedData: undefined,\n};\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n\n/**\n * Execute all variant loaders and merge their payloads.\n * `loadedData` is applied last so host-level overrides win.\n */\nexport async function executeVariantLoaders(\n loaders: VariantLoader[] | undefined,\n loadedData?: Record<string, unknown>,\n): Promise<Record<string, unknown> | undefined> {\n const hasLoaders = !!loaders && loaders.length > 0;\n if (!hasLoaders) {\n return loadedData;\n }\n\n const results = await Promise.all(loaders.map((loader) => loader()));\n const mergedFromLoaders = results.reduce<Record<string, unknown>>(\n (acc, result) => ({ ...acc, ...result }),\n {},\n );\n\n return loadedData ? { ...mergedFromLoaders, ...loadedData } : mergedFromLoaders;\n}\n\n/**\n * Resolve a full runtime state (loader execution + render) in one async call.\n * This is useful for testing and for hook/component orchestration.\n */\nexport async function resolvePreviewRuntimeState(\n options: PreviewRuntimeOptions,\n): Promise<PreviewRuntimeState> {\n const { variant, loadedData } = options;\n if (!variant) {\n return EMPTY_STATE;\n }\n\n try {\n const mergedLoadedData = await executeVariantLoaders(variant.loaders, loadedData);\n const content = variant.render({ loadedData: mergedLoadedData });\n return {\n content,\n isLoading: false,\n error: null,\n loadedData: mergedLoadedData,\n };\n } catch (error) {\n return {\n content: null,\n isLoading: false,\n error: toError(error),\n loadedData: undefined,\n };\n }\n}\n\n/**\n * Hook for rendering a preview variant with loader support.\n */\nexport function usePreviewVariantRuntime(\n options: PreviewRuntimeOptions,\n): PreviewRuntimeState {\n const { variant, loadedData } = options;\n const [state, setState] = useState<PreviewRuntimeState>(EMPTY_STATE);\n\n useEffect(() => {\n let cancelled = false;\n\n if (!variant) {\n setState(EMPTY_STATE);\n return () => {\n cancelled = true;\n };\n }\n\n const hasLoaders = !!variant.loaders && variant.loaders.length > 0;\n setState({\n content: null,\n isLoading: hasLoaders,\n error: null,\n loadedData: undefined,\n });\n\n resolvePreviewRuntimeState({ variant, loadedData }).then((nextState) => {\n if (!cancelled) {\n setState(nextState);\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [variant, loadedData]);\n\n return state;\n}\n\ninterface PreviewVariantRuntimeProps extends PreviewRuntimeOptions {\n children: (state: PreviewRuntimeState) => ReactNode;\n}\n\n/**\n * Render-prop component wrapper around `usePreviewVariantRuntime`.\n */\nexport function PreviewVariantRuntime({\n variant,\n loadedData,\n children,\n}: PreviewVariantRuntimeProps) {\n const state = usePreviewVariantRuntime({ variant, loadedData });\n return <>{children(state)}</>;\n}\n"],"mappings":";AAIO,IAAM,QAAQ;AAAA;AAAA,EAEnB,MAAM;AAAA;AAAA,EAGN,WAAW;AAAA;AAAA,EAGX,eAAe;AAAA;AAAA,EAGf,qBAAqB;AAAA;AAAA,EAGrB,eAAe;AAAA;AAAA,EAGf,SAAS;AAAA;AAAA,EAGT,YAAY;AAAA;AAAA,EAGZ,kBAAkB;AAAA;AAAA,EAGlB,YAAY;AAAA;AAAA,EAGZ,cAAc;AAAA;AAAA,EAGd,SAAS;AAAA;AAAA,EAGT,eAAe;AAAA;AAAA,EAGf,cAAc;AAAA;AAAA,EAGd,aAAa;AAAA;AAAA,EAGb,gBAAgB;AAAA;AAAA,EAGhB,UAAU;AAAA;AAAA,EAGV,SAAS;AAAA;AAAA,EAGT,cAAc;AAAA;AAAA,EAGd,eAAe;AAAA;AAAA,EAGf,gBAAgB;AAAA;AAAA,EAGhB,eAAe;AAAA;AAAA,EAGf,oBAAoB;AAAA;AAAA,EAGpB,qBAAqB;AAAA;AAAA,EAGrB,qBAAqB;AACvB;AAQO,IAAM,WAAW;AAAA;AAAA,EAEtB,UAAU;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA;AAAA,EAGA,eAAe;AAAA;AAAA,EAGf,UAAU;AAAA;AAAA,EAGV,eAAe,IAAI,KAAK;AAAA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OAAO;AAAA,MACP,YAAY;AAAA,IACd,CAAC;AAED,+BAA2B,EAAE,SAAS,WAAW,CAAC,EAAE,KAAK,CAAC,cAAc;AACtE,UAAI,CAAC,WAAW;AACd,iBAAS,SAAS;AAAA,MACpB;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO;AACT;AASO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,UAAAA;AACF,GAA+B;AAC7B,QAAM,QAAQ,yBAAyB,EAAE,SAAS,WAAW,CAAC;AAC9D,SAAO,gCAAG,UAAAA,UAAS,KAAK,GAAE;AAC5B;","names":["children"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fragments-sdk/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Core types, schemas, and runtime API for Fragments component definitions",
|
|
6
|
+
"author": "Conan McNicholl",
|
|
7
|
+
"homepage": "https://usefragments.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ConanMcN/fragments"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"fragments",
|
|
31
|
+
"design-system",
|
|
32
|
+
"component-library",
|
|
33
|
+
"react",
|
|
34
|
+
"types",
|
|
35
|
+
"schema",
|
|
36
|
+
"ai",
|
|
37
|
+
"mcp"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"zod": "^3.24.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@fragments-sdk/context": ">=0.4.0",
|
|
44
|
+
"@storybook/csf": "^0.1.0",
|
|
45
|
+
"react": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"@fragments-sdk/context": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@storybook/csf": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@storybook/csf": "^0.1.12",
|
|
60
|
+
"@types/node": "^22.0.0",
|
|
61
|
+
"@types/react": "^18.3.0",
|
|
62
|
+
"react": "^18.3.0",
|
|
63
|
+
"tsup": "^8.3.5",
|
|
64
|
+
"typescript": "^5.7.2",
|
|
65
|
+
"vitest": "^2.1.8",
|
|
66
|
+
"@fragments-sdk/context": "0.4.2"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsup",
|
|
70
|
+
"dev": "tsup --watch",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"typecheck": "tsc --noEmit",
|
|
73
|
+
"clean": "rm -rf dist"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
executeVariantLoaders,
|
|
4
|
+
resolvePreviewRuntimeState,
|
|
5
|
+
type PreviewVariantLike,
|
|
6
|
+
} from "../preview-runtime.js";
|
|
7
|
+
|
|
8
|
+
describe("executeVariantLoaders", () => {
|
|
9
|
+
it("returns host loadedData when no loaders are defined", async () => {
|
|
10
|
+
const loadedData = { source: "host", count: 1 };
|
|
11
|
+
const result = await executeVariantLoaders(undefined, loadedData);
|
|
12
|
+
expect(result).toEqual(loadedData);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("merges loader results and applies host loadedData last", async () => {
|
|
16
|
+
const result = await executeVariantLoaders(
|
|
17
|
+
[
|
|
18
|
+
async () => ({ count: 1, fromFirst: true }),
|
|
19
|
+
async () => ({ count: 2, fromSecond: true }),
|
|
20
|
+
],
|
|
21
|
+
{ count: 3, fromHost: true },
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(result).toEqual({
|
|
25
|
+
count: 3,
|
|
26
|
+
fromFirst: true,
|
|
27
|
+
fromSecond: true,
|
|
28
|
+
fromHost: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("resolvePreviewRuntimeState", () => {
|
|
34
|
+
it("renders variants with no loaders", async () => {
|
|
35
|
+
const variant: PreviewVariantLike = {
|
|
36
|
+
render: () => "Preview content",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const state = await resolvePreviewRuntimeState({ variant });
|
|
40
|
+
|
|
41
|
+
expect(state.isLoading).toBe(false);
|
|
42
|
+
expect(state.error).toBeNull();
|
|
43
|
+
expect(state.content).toBe("Preview content");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("renders with successful loaders", async () => {
|
|
47
|
+
const variant: PreviewVariantLike = {
|
|
48
|
+
loaders: [async () => ({ label: "from-loader" })],
|
|
49
|
+
render: (options) => `Loaded: ${String(options?.loadedData?.label)}`,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const state = await resolvePreviewRuntimeState({ variant });
|
|
53
|
+
|
|
54
|
+
expect(state.error).toBeNull();
|
|
55
|
+
expect(state.loadedData).toEqual({ label: "from-loader" });
|
|
56
|
+
expect(state.content).toBe("Loaded: from-loader");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("returns an error when a loader rejects", async () => {
|
|
60
|
+
const variant: PreviewVariantLike = {
|
|
61
|
+
loaders: [async () => { throw new Error("loader failed"); }],
|
|
62
|
+
render: () => "should not render",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const state = await resolvePreviewRuntimeState({ variant });
|
|
66
|
+
|
|
67
|
+
expect(state.content).toBeNull();
|
|
68
|
+
expect(state.error?.message).toContain("loader failed");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("returns an error when render throws", async () => {
|
|
72
|
+
const variant: PreviewVariantLike = {
|
|
73
|
+
render: () => {
|
|
74
|
+
throw new Error("render failed");
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const state = await resolvePreviewRuntimeState({ variant });
|
|
79
|
+
|
|
80
|
+
expect(state.content).toBeNull();
|
|
81
|
+
expect(state.error?.message).toContain("render failed");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("normalizes non-Error throwables", async () => {
|
|
85
|
+
const variant: PreviewVariantLike = {
|
|
86
|
+
loaders: [async () => { throw "string-failure"; }],
|
|
87
|
+
render: () => "never",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const state = await resolvePreviewRuntimeState({ variant });
|
|
91
|
+
expect(state.error).not.toBeNull();
|
|
92
|
+
expect(state.error?.message).toContain("string-failure");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("uses host data as override input in render options", async () => {
|
|
96
|
+
const renderSpy = vi.fn((options?: { loadedData?: Record<string, unknown> }) => options?.loadedData);
|
|
97
|
+
const variant: PreviewVariantLike = {
|
|
98
|
+
loaders: [async () => ({ count: 1 })],
|
|
99
|
+
render: renderSpy,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const state = await resolvePreviewRuntimeState({
|
|
103
|
+
variant,
|
|
104
|
+
loadedData: { count: 2, source: "host" },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(renderSpy).toHaveBeenCalledTimes(1);
|
|
108
|
+
expect(state.loadedData).toEqual({ count: 2, source: "host" });
|
|
109
|
+
expect(state.content).toEqual({ count: 2, source: "host" });
|
|
110
|
+
});
|
|
111
|
+
});
|