| 548 | } |
| 549 | |
| 550 | func parseHexColor(hex string) (r, g, b float64, ok bool) { |
| 551 | hex = strings.TrimPrefix(hex, "#") |
| 552 | if len(hex) == 3 { |
| 553 | hex = string([]byte{hex[0], hex[0], hex[1], hex[1], hex[2], hex[2]}) |
| 554 | } |
| 555 | |
| 556 | if len(hex) != 6 { |
| 557 | return 0, 0, 0, false |
| 558 | } |
| 559 | |
| 560 | rgb, err := strconv.ParseUint(hex, 16, 24) |
| 561 | if err != nil { |
| 562 | return 0, 0, 0, false |
| 563 | } |
| 564 | |
| 565 | return float64((rgb>>16)&0xFF) / 255.0, float64((rgb>>8)&0xFF) / 255.0, float64(rgb&0xFF) / 255.0, true |
| 566 | } |
| 567 | |
| 568 | func invalidf(format string, args ...any) error { |
| 569 | return ValidationError(fmt.Sprintf(format, args...)) |