Merge pull request #2487 from melsonic/issue-2481

fix: made gradients work in sketch mode
This commit is contained in:
Alexander Wang 2025-04-14 11:35:01 -07:00 committed by GitHub
commit 31519e9d63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 138 additions and 0 deletions

View file

@ -36,6 +36,7 @@
- fixes inconsistencies when objects were double quoted [#2390](https://github.com/terrastruct/d2/pull/2390) - fixes inconsistencies when objects were double quoted [#2390](https://github.com/terrastruct/d2/pull/2390)
- fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426) - fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426)
- fixes panic when classes were mixed with layers incorrectly [#2448](https://github.com/terrastruct/d2/pull/2448) - fixes panic when classes were mixed with layers incorrectly [#2448](https://github.com/terrastruct/d2/pull/2448)
- fixes panic when gradient colors are used in sketch mode [#2481](https://github.com/terrastruct/d2/pull/2487)
- fixes panic using glob ampersand filters with composite values [#2489](https://github.com/terrastruct/d2/pull/2489) - fixes panic using glob ampersand filters with composite values [#2489](https://github.com/terrastruct/d2/pull/2489)
- Formatter: - Formatter:
- fixes substitutions in quotes surrounded by text [#2462](https://github.com/terrastruct/d2/pull/2462) - fixes substitutions in quotes surrounded by text [#2462](https://github.com/terrastruct/d2/pull/2462)

View file

@ -1357,6 +1357,14 @@ item -> customer: is(Adult)
customer -> item: true customer -> item: true
`, `,
}, },
{
name: "test-gradient-fill-values-in-sketch-mode",
script: `
x->y
x.style.fill: "linear-gradient(#000000,#ffffff)"
y.style.fill: "linear-gradient(#ffffff,#000000)"
`,
},
} }
runa(t, tcs) runa(t, tcs)
} }

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 53 KiB

View file

@ -86,6 +86,11 @@ func darkenCSS(colorString string) (string, error) {
} }
func LuminanceCategory(colorString string) (string, error) { func LuminanceCategory(colorString string) (string, error) {
// check if colorString matches the `url('#grad-<sha1-hash>')` format
// which is used to refer to a <linearGradient> or <radialGradient> element.
if IsURLGradientID(colorString) {
return "normal", nil
}
l, err := Luminance(colorString) l, err := Luminance(colorString)
if err != nil { if err != nil {
return "", err return "", err

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)
}