Files
InsanityLab-web/src/lib/style-presets.ts
T
Adriano 30b509436e contenuti: aggiunge size xl/xxl e allineamento (con giustificato)
- style-presets: size += xl, xxl; align += justify
- global.css: .cs-size-xl (1.5em), .cs-size-xxl (2em), .cs-align-justify
- content-seed: 'align' nei default styleOptions dei tag testo/html, così il
  picker orientamento (sx/centrato/dx/giustificato) compare nell'editor
- Base.astro: sincronizza la copia hardcoded degli stili nell'editor inline

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 23:48:58 +02:00

32 lines
1.2 KiB
TypeScript

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