Merge pull request #2487 from melsonic/issue-2481
fix: made gradients work in sketch mode
This commit is contained in:
commit
31519e9d63
5 changed files with 138 additions and 0 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
118
d2renderers/d2sketch/testdata/test-gradient-fill-values-in-sketch-mode/sketch.exp.svg
vendored
Normal file
118
d2renderers/d2sketch/testdata/test-gradient-fill-values-in-sketch-mode/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 53 KiB |
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue