(primaryColor: PrimaryColor, customColor?: string)
| 54 | * 应用主题色类名;当主题色为 custom 时同步写入自定义色变量。 |
| 55 | */ |
| 56 | export function applyPrimaryColor(primaryColor: PrimaryColor, customColor?: string): void { |
| 57 | document.body.className = document.body.className.replace(/theme-\w+/g, '').trim() |
| 58 | document.body.classList.add(`theme-${primaryColor}`) |
| 59 | |
| 60 | if (primaryColor === 'custom' && typeof customColor === 'string' && customColor) { |
| 61 | applyCustomColor(customColor) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | function hexToRgb(hex: string): { r: number; g: number; b: number } | null { |
| 66 | const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) |
no test coverage detected