()
| 251 | } |
| 252 | |
| 253 | func (t *ThemeColors) validate() (*runtimev1.ThemeColors, error) { |
| 254 | // Create a new map for the final variables with deprecated names mapped to new ones |
| 255 | finalVariables := make(map[string]string) |
| 256 | |
| 257 | for k, v := range t.Variables { |
| 258 | if !allowedCSSVariables[k] { |
| 259 | return nil, fmt.Errorf("invalid CSS variable: %q", k) |
| 260 | } |
| 261 | _, err := csscolorparser.Parse(v) |
| 262 | if err != nil { |
| 263 | return nil, fmt.Errorf("invalid value %q for CSS variable %q: %w", v, k, err) |
| 264 | } |
| 265 | |
| 266 | // Check if this is a deprecated variable that should be mapped |
| 267 | if newNames, isDeprecated := deprecatedCSSVariables[k]; isDeprecated { |
| 268 | for _, newName := range newNames { |
| 269 | // Only map to the new name if it's not already explicitly set |
| 270 | if _, alreadySet := t.Variables[newName]; !alreadySet { |
| 271 | finalVariables[newName] = v |
| 272 | } |
| 273 | } |
| 274 | // Don't output the deprecated name |
| 275 | } else { |
| 276 | finalVariables[k] = v |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if t.Primary != "" { |
| 281 | _, err := csscolorparser.Parse(t.Primary) |
| 282 | if err != nil { |
| 283 | return nil, fmt.Errorf("invalid value %q for primary: %w", t.Primary, err) |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | if t.Secondary != "" { |
| 288 | _, err := csscolorparser.Parse(t.Secondary) |
| 289 | if err != nil { |
| 290 | return nil, fmt.Errorf("invalid value %q for secondary: %w", t.Secondary, err) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return &runtimev1.ThemeColors{ |
| 295 | Primary: t.Primary, |
| 296 | Secondary: t.Secondary, |
| 297 | Variables: finalVariables, |
| 298 | }, nil |
| 299 | } |
no test coverage detected