fix: made gradients work in sketch mode

This commit is contained in:
melsonic 2025-04-08 20:33:10 +05:30
parent 1a13e0a9bc
commit 8f64c02dd8
No known key found for this signature in database
GPG key ID: DFA426742F621CD7
2 changed files with 15 additions and 3 deletions

View file

@ -24,9 +24,15 @@ func (o *ThemableSketchOverlay) Render() (string, error) {
if color.IsThemeColor(o.fill) { if color.IsThemeColor(o.fill) {
o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", o.fill) // e.g. sketch-overlay-B3 o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", o.fill) // e.g. sketch-overlay-B3
} else { } else {
lc, err := color.LuminanceCategory(o.fill) var lc string
if err != nil { if color.IsUrlGradientId(o.fill) {
return "", err lc = "normal"
} else {
var err error
lc, err = color.LuminanceCategory(o.fill)
if err != nil {
return "", err
}
} }
o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", lc) // e.g. sketch-overlay-dark o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", lc) // e.g. sketch-overlay-dark
} }

View file

@ -246,3 +246,9 @@ var GradientRegex = regexp.MustCompile(`^(linear|radial)-gradient\((.+)\)$`)
func IsGradient(color string) bool { func IsGradient(color string) bool {
return GradientRegex.MatchString(color) return GradientRegex.MatchString(color)
} }
var UrlGradientId = regexp.MustCompile(`^url\('#grad-[a-f0-9]{40}'\)$`)
func IsUrlGradientId(color string) bool {
return UrlGradientId.MatchString(color)
}