export const STYLE_GROUPS = { size: ['s', 'm', 'l'], color: ['accent', 'accent-dark', 'dark', 'heading', 'text', 'text-light', 'white'], weight: ['normal', 'bold'], style: ['normal', 'italic'], align: ['left', 'center', 'right'], } as const; export type StyleGroup = keyof typeof STYLE_GROUPS; export function validateStyles(input: unknown): | { ok: true; styles: Record } | { ok: false; error: string } { if (typeof input !== 'object' || input === null || Array.isArray(input)) { return { ok: false, error: 'Stili non validi.' }; } const out: Record = {}; for (const [k, v] of Object.entries(input)) { const allowed = (STYLE_GROUPS as Record)[k]; if (!allowed) return { ok: false, error: `Gruppo stile sconosciuto: ${k}` }; if (typeof v !== 'string' || !allowed.includes(v)) { return { ok: false, error: `Valore non ammesso per ${k}: ${String(v)}` }; } out[k] = v; } return { ok: true, styles: out }; } export function stylesToClasses(styles: Record): string { return Object.entries(styles).map(([k, v]) => `cs-${k}-${v}`).join(' '); }