@youwen/ai-design-system
Version:
Enterprise AI-driven design system with comprehensive design tokens
138 lines (137 loc) • 3.86 kB
TypeScript
/**
* AI验证系统类型定义
*/
/// <reference types="react" />
export interface ValidationResult {
isValid: boolean;
errors: string[];
warnings: string[];
suggestions: string[];
metrics: ValidationMetrics;
componentType: string;
timestamp: string;
}
export interface ValidationMetrics {
accessibilityScore: number;
performanceScore: number;
designConsistency: number;
totalIssues: number;
}
export interface ComponentValidationReport extends ValidationResult {
componentId: string;
}
export interface ValidationConfig {
enableAccessibilityCheck: boolean;
enablePerformanceCheck: boolean;
enableDesignConsistencyCheck: boolean;
wcagLevel: 'A' | 'AA' | 'AAA';
contrastThreshold: number;
}
export interface DesignTokenValidation {
colors: {
isValidBrandColor: (color: string) => boolean;
isValidSemanticColor: (color: string) => boolean;
isValidNeutralColor: (color: string) => boolean;
};
spacing: {
isValidSpacing: (value: string | number) => boolean;
getValidSpacingValues: () => number[];
};
typography: {
isValidFontSize: (size: string | number) => boolean;
isValidFontWeight: (weight: string | number) => boolean;
isValidLineHeight: (height: string | number) => boolean;
};
}
export interface AccessibilityRule {
id: string;
name: string;
description: string;
severity: 'error' | 'warning' | 'info';
check: (element: any, context: any) => ValidationIssue | null;
}
export interface ValidationIssue {
ruleId: string;
severity: 'error' | 'warning' | 'info';
message: string;
suggestion?: string;
element?: string;
}
export interface PerformanceMetrics {
renderTime: number;
memoryUsage: number;
reRenderCount: number;
bundleSize?: number;
}
export interface ValidationContext {
componentType: string;
props: Record<string, any>;
children?: React.ReactNode;
parentContext?: ValidationContext;
theme: 'light' | 'dark';
viewport: 'mobile' | 'tablet' | 'desktop';
}
export interface ValidationRule {
id: string;
name: string;
description: string;
category: 'accessibility' | 'performance' | 'design' | 'best-practices';
severity: 'error' | 'warning' | 'info';
enabled: boolean;
validate: (context: ValidationContext) => ValidationIssue[];
}
export interface ValidationEngine {
rules: ValidationRule[];
config: ValidationConfig;
validate: (context: ValidationContext) => ValidationResult;
addRule: (rule: ValidationRule) => void;
removeRule: (ruleId: string) => void;
updateConfig: (config: Partial<ValidationConfig>) => void;
}
export interface ComponentCompliance {
wcag21: {
levelA: boolean;
levelAA: boolean;
levelAAA: boolean;
};
designSystem: {
colorCompliance: boolean;
spacingCompliance: boolean;
typographyCompliance: boolean;
};
performance: {
loadTime: number;
renderTime: number;
memoryEfficiency: number;
};
}
export interface ValidationSummary {
totalComponents: number;
passedComponents: number;
failedComponents: number;
totalIssues: number;
issuesByCategory: {
accessibility: number;
performance: number;
design: number;
bestPractices: number;
};
averageScores: {
accessibility: number;
performance: number;
designConsistency: number;
overall: number;
};
complianceRates: {
wcagAA: number;
designSystem: number;
bestPractices: number;
};
}
export interface ValidationReport {
summary: ValidationSummary;
components: ComponentValidationReport[];
timestamp: string;
version: string;
config: ValidationConfig;
}