update gradient color stop validity check
This commit is contained in:
parent
9f66199777
commit
909eeb00af
2 changed files with 16 additions and 11 deletions
|
|
@ -512,7 +512,19 @@ var NamedColors = []string{
|
|||
var ColorHexRegex = regexp.MustCompile(`^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$`)
|
||||
|
||||
func ValidColor(color string) bool {
|
||||
if !go2.Contains(NamedColors, strings.ToLower(color)) && !ColorHexRegex.MatchString(color) && !IsGradient(color) {
|
||||
|
||||
if IsGradient(color) {
|
||||
gradient, err := ParseGradient(color)
|
||||
for _, colorStop := range gradient.ColorStops {
|
||||
_, err = csscolorparser.Parse(colorStop.Color)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err == nil
|
||||
}
|
||||
|
||||
if !go2.Contains(NamedColors, strings.ToLower(color)) && !ColorHexRegex.MatchString(color) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mazznoer/csscolorparser"
|
||||
)
|
||||
|
||||
type Gradient struct {
|
||||
|
|
@ -243,15 +241,10 @@ func UniqueGradientID(cssGradient string) string {
|
|||
return "grad-" + hash
|
||||
}
|
||||
|
||||
var GradientRegex = regexp.MustCompile(`^(linear|radial)-gradient\((.+)\)$`)
|
||||
|
||||
func IsGradient(color string) bool {
|
||||
gradient, err := ParseGradient(color)
|
||||
for _, colorStop := range gradient.ColorStops {
|
||||
_, err = csscolorparser.Parse(colorStop.Color)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err == nil
|
||||
return GradientRegex.MatchString(color)
|
||||
}
|
||||
|
||||
var URLGradientID = regexp.MustCompile(`^url\('#grad-[a-f0-9]{40}'\)$`)
|
||||
|
|
|
|||
Loading…
Reference in a new issue