/**
 * design/frontmatter-schema.mjs — Zod schema for DESIGN.md YAML frontmatter (C2).
 *
 * DESIGN.md is the project-root design contract (Stitch 9-section format). The
 * YAML frontmatter carries the machine-parseable bits (tokens, palette,
 * anti-patterns); the prose body carries the human-facing narrative. See
 * `docs/frameworks/Design-system/overview.md` §2.3 / §10.1 for the rationale.
 *
 * Schema is intentionally permissive on additive fields (not `.strict()`): tools
 * and future milestones may introduce new frontmatter keys, and a stale
 * validator should not block a newer authoring flow. The authored keys are
 * checked; unknown keys pass through silently.
 *
 * The flat-ish shape below mirrors `design/schema.mjs` for design-scan tokens:
 * small objects of sorted arrays where there's no richer structure yet, and a
 * strict `meta` block so human/agent drift on the required identity fields
 * surfaces at validate time rather than lint time.
 *
 * v1 keeps `components` open-ended (any keyed record) and `motion` as named
 * duration/easing pairs. Richer structure (dark/light pairing, tonal ramps,
 * keyframe tracks) is deferred.
 */
import { z } from 'zod';
// --- Shared primitives -------------------------------------------------------
const NonEmptyString = z.string().min(1);
// Hex color: #RGB, #RRGGBB, or #RRGGBBAA.  OKLCH/rgb()/hsl() strings also valid
// because the body may reference color-space-specific values we don't want to
// police here; anything non-empty is accepted.  Hex is the cheapest canonical
// form for apt-tools design-lint downstream.
const ColorString = NonEmptyString;
const PixelOrRem = NonEmptyString;
// --- meta (strict) -----------------------------------------------------------
export const MetaSchema = z
    .object({
    name: NonEmptyString,
    version: NonEmptyString,
    updated: NonEmptyString, // ISO-8601 date or datetime; free-form by design
    description: NonEmptyString.optional(),
    inspiration: NonEmptyString.optional(), // typeui-sh slug or free-form note
})
    .strict();
// --- tokens.colors -----------------------------------------------------------
const ColorStatusSchema = z
    .object({
    success: ColorString.optional(),
    warning: ColorString.optional(),
    danger: ColorString.optional(),
    info: ColorString.optional(),
})
    .passthrough();
export const ColorsSchema = z
    .object({
    bg: ColorString,
    surface: ColorString,
    accent: ColorString,
    text: ColorString,
    border: ColorString,
    status: ColorStatusSchema.optional(),
})
    .passthrough();
// --- tokens.typography -------------------------------------------------------
export const TypographyFamiliesSchema = z
    .object({
    primary: NonEmptyString,
    display: NonEmptyString.optional(),
    mono: NonEmptyString.optional(),
})
    .passthrough();
export const TypographySchema = z
    .object({
    families: TypographyFamiliesSchema,
    scale: z.array(PixelOrRem).min(3), // at least {body, heading, display}
    weights: z
        .union([z.array(z.number().int().positive()), z.record(z.string(), z.number().positive())])
        .optional(),
    lineHeight: z.record(z.string(), NonEmptyString).optional(),
})
    .passthrough();
// --- tokens.spacing / radius / shadow / motion -------------------------------
export const SpacingSchema = z.array(PixelOrRem).min(2);
export const RadiusSchema = z.record(z.string(), PixelOrRem);
export const ShadowSchema = z.record(z.string(), NonEmptyString);
export const MotionEasingSchema = z.record(z.string(), NonEmptyString);
export const MotionSchema = z
    .object({
    duration: z.record(z.string(), NonEmptyString).optional(),
    easing: MotionEasingSchema.optional(),
})
    .passthrough();
// --- tokens (required) -------------------------------------------------------
export const TokensSchema = z
    .object({
    colors: ColorsSchema,
    typography: TypographySchema,
    spacing: SpacingSchema,
    radius: RadiusSchema.optional(),
    shadow: ShadowSchema.optional(),
    motion: MotionSchema.optional(),
})
    .passthrough();
// --- components --------------------------------------------------------------
//
// Open-ended record: each key is a component name (`button`, `card`, `input`),
// each value is a record of token overrides or variant definitions.  We don't
// prescribe the inner shape in v1 — enforcing one would constrain what the
// style skills in examples/by-source/typeui-sh/ can express.
export const ComponentsSchema = z.record(z.string(), z.record(z.string(), z.unknown()));
// --- antiPatterns ------------------------------------------------------------
//
// Structured catalog consumed by C11 `apt-tools design-lint`.  Each entry is
// specific enough for a post-generation grep to find violations.
export const AntiPatternCategorySchema = z.enum([
    'color',
    'typography',
    'layout',
    'content',
    'motion',
    'interaction',
]);
export const AntiPatternSchema = z
    .object({
    id: NonEmptyString,
    category: AntiPatternCategorySchema,
    pattern: NonEmptyString, // regex or css-match literal
    why: NonEmptyString,
    rewrite: NonEmptyString,
})
    .strict();
export const AntiPatternsSchema = z.array(AntiPatternSchema);
// --- inspiration -------------------------------------------------------------
//
// Names of design styles the author drew from — typically typeui-sh slugs
// (`paper`, `bento`, `clean`, `neobrutalism`, …) so the variant-generator can
// reach for a vendored style skill when expanding `apt:mockup --variants N`.
export const InspirationSchema = z.array(NonEmptyString);
// --- root --------------------------------------------------------------------
export const DesignFrontmatterSchema = z
    .object({
    meta: MetaSchema,
    tokens: TokensSchema,
    components: ComponentsSchema.optional(),
    antiPatterns: AntiPatternsSchema.optional(),
    inspiration: InspirationSchema.optional(),
})
    .passthrough();
/**
 * Validate a parsed YAML object as DESIGN.md frontmatter.
 *
 * @param {unknown} data — the YAML.parse() output
 * @returns {import('zod').SafeParseReturnType<unknown, unknown>}
 */
export function validateDesignFrontmatter(data) {
    return DesignFrontmatterSchema.safeParse(data);
}
//# sourceMappingURL=frontmatter-schema.mjs.map