trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
55 lines • 2.12 kB
TypeScript
/**
* Constraint Application — Narrows shadcn component Zod enums based on brand tokens.
*
* The core transformation: shadcn's Button accepts z.enum(["primary","secondary","danger"])
* → a brand-constrained catalog narrows it to z.enum(["primary","danger"]) based on
* which token roles exist in the graph.
*
* @module trellis/plugins/brand
*/
import { z } from 'zod';
/**
* Maps component name → { propName: tokenType }.
* Only components/props listed here are narrowed; everything else passes through.
*/
export declare const CONSTRAINT_MAP: Record<string, Record<string, string>>;
/**
* When token role names don't match shadcn enum values 1:1, this map provides
* the translation. A role of "destructive" maps to both "destructive" and "danger"
* (whichever the shadcn component actually uses).
*/
export declare const ROLE_ALIASES: Record<string, string[]>;
/**
* Extract enum values from a Zod schema. Handles:
* - z.enum([...])
* - z.enum([...]).nullable()
* - z.enum([...]).optional()
* - z.enum([...]).nullable().optional()
*
* Returns null if the schema is not an enum type.
*/
export declare function extractEnumValues(schema: z.ZodType): string[] | null;
/**
* Narrow an enum to only values that match available token roles.
*
* @param originalEnum - The full set of enum values from the shadcn component
* @param availableRoles - Token roles present in the brand guide
* @returns Narrowed enum values. Falls back to first original value if nothing matches.
*/
export declare function constrainEnum(originalEnum: string[], availableRoles: string[]): string[];
/**
* Given a component definition and the available tokens grouped by type,
* return a new definition with narrowed Zod enum props.
*
* If the component has no constraints in CONSTRAINT_MAP, returns the original.
*/
export declare function constrainComponentDef(componentName: string, def: {
props: z.ZodType;
[key: string]: unknown;
}, tokensByType: Record<string, Array<{
role: string;
}>>): {
props: z.ZodType;
[key: string]: unknown;
};
//# sourceMappingURL=constraints.d.ts.map