w1-system-font-validator
Version:
VS Code extension for validating W1 System font variables (both fontConfig.json and localFontConfig.json)
111 lines (98 loc) • 3.19 kB
text/typescript
/**
* Type definitions for W1 Font System configurations
* Supports both fontConfig.json and localFontConfig.json
*/
// NEW SYSTEM: Font Config (Package-based fonts)
export interface FontConfig {
generated: string;
fontConfig: string;
validVariables: string[];
roles: Record<string, FontRole>;
summary: {
totalRoles: number;
totalVariables: number;
fontsWithItalics: number;
};
}
export interface FontRole {
fontId?: string;
displayName: string;
cssFamily: string;
hasItalics: boolean;
availableWeights: Record<string, WeightInfo | null>; // e.g., {"400": {weight: 400, style: "normal"}, "400_italic": {weight: 400, style: "italic"}}
variables: {
family: string; // e.g., "--fontfamily_primary"
// No more weight-specific variables - using CSS font-weight instead
};
}
export interface WeightInfo {
weight: number;
style: "normal" | "italic";
}
// Local Font Config (Local file-based fonts)
export interface LocalFontConfig {
generated: string;
fontConfig?: string;
validVariables: string[];
roles: Record<string, string | null>;
detailedRoles?: Record<string, LocalFontRole>;
fonts: Record<string, LocalFont>;
summary: {
totalFonts: number;
totalVariants: number;
totalRoles: number;
assignedRoles: number;
totalVariables?: number;
fontsWithItalics?: number;
};
}
export interface LocalFontRole {
fontId: string;
displayName: string;
cssFamily: string;
hasItalics: boolean;
availableWeights: Record<string, WeightInfo | null>; // Unified object format (same as FontRole)
variables: {
family: string; // e.g., "--fontfamily_primary_local"
};
}
export interface LocalFont {
fontName: string;
displayName: string;
cssFamily: string;
variants: FontVariant[];
directory: string;
lastUpdated: string;
}
export interface FontVariant {
weight: number;
style: "normal" | "italic";
filename: string;
}
// Unified project configuration
export interface ProjectFontConfig {
hasFontConfig: boolean;
hasLocalFontConfig: boolean;
fontConfigPath?: string;
localFontConfigPath?: string;
fontConfig?: FontConfig;
localFontConfig?: LocalFontConfig;
}
// Validation patterns for the new system
export interface ValidationPattern {
// Font-family variables (NEW SYSTEM)
fontFamilyPattern: RegExp; // matches --fontfamily_*
// CSS font-weight validation
validWeights: string[]; // ["100", "200", "300", "400", "500", "600", "700", "800", "900"]
// Old patterns (for backward compatibility detection)
deprecatedWeightPattern?: RegExp; // matches old --font_primary_bold patterns
}
export interface ValidationError {
type: 'invalid-font-family' | 'invalid-weight' | 'deprecated-pattern' | 'missing-config';
message: string;
suggestions?: string[];
range: {
start: { line: number; character: number };
end: { line: number; character: number };
};
}