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})$`)
|
var ColorHexRegex = regexp.MustCompile(`^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$`)
|
||||||
|
|
||||||
func ValidColor(color string) bool {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mazznoer/csscolorparser"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gradient struct {
|
type Gradient struct {
|
||||||
|
|
@ -243,15 +241,10 @@ func UniqueGradientID(cssGradient string) string {
|
||||||
return "grad-" + hash
|
return "grad-" + hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var GradientRegex = regexp.MustCompile(`^(linear|radial)-gradient\((.+)\)$`)
|
||||||
|
|
||||||
func IsGradient(color string) bool {
|
func IsGradient(color string) bool {
|
||||||
gradient, err := ParseGradient(color)
|
return GradientRegex.MatchString(color)
|
||||||
for _, colorStop := range gradient.ColorStops {
|
|
||||||
_, err = csscolorparser.Parse(colorStop.Color)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err == nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var URLGradientID = regexp.MustCompile(`^url\('#grad-[a-f0-9]{40}'\)$`)
|
var URLGradientID = regexp.MustCompile(`^url\('#grad-[a-f0-9]{40}'\)$`)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue