From 19c53d51854f8ab2d9c949563faffbbe5164235d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Thu, 12 Jan 2023 11:19:34 +0100 Subject: [PATCH] added missing colors conversion --- d2renderers/d2svg/d2svg.go | 33 +++++++++++++++++++-- lib/color/color.go | 61 ++++++++++++++++++++++++++++---------- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index ade6a5e0d..cf547be26 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -1336,6 +1336,7 @@ func singleThemeRulesets(themeID int64) (rulesets string, err error) { ) // Sketch style specific rulesets + // B lc, err := color.LuminanceCategory(theme.Colors.B1) if err != nil { return "", err @@ -1367,6 +1368,36 @@ func singleThemeRulesets(themeID int64) (rulesets string, err error) { } out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.B6, lc, blendMode(lc)) + // AA + lc, err = color.LuminanceCategory(theme.Colors.AA2) + if err != nil { + return "", err + } + out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.AA2, lc, blendMode(lc)) + lc, err = color.LuminanceCategory(theme.Colors.AA4) + if err != nil { + return "", err + } + out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.AA4, lc, blendMode(lc)) + lc, err = color.LuminanceCategory(theme.Colors.AA5) + if err != nil { + return "", err + } + out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.AA5, lc, blendMode(lc)) + + // AB + lc, err = color.LuminanceCategory(theme.Colors.AB4) + if err != nil { + return "", err + } + out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.AB4, lc, blendMode(lc)) + lc, err = color.LuminanceCategory(theme.Colors.AB5) + if err != nil { + return "", err + } + out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.AB5, lc, blendMode(lc)) + + // Neutrals lc, err = color.LuminanceCategory(theme.Colors.Neutrals.N1) if err != nil { return "", err @@ -1403,8 +1434,6 @@ func singleThemeRulesets(themeID int64) (rulesets string, err error) { } out += fmt.Sprintf(".sketch-overlay-%s{fill:url(#streaks-%s);mix-blend-mode:%s}", color.N7, lc, blendMode(lc)) - // TODO Add the rest of the colors so we can allow the user to specify theme colors too - return out, nil } diff --git a/lib/color/color.go b/lib/color/color.go index ae3a07f55..22f2a21c6 100644 --- a/lib/color/color.go +++ b/lib/color/color.go @@ -16,22 +16,53 @@ func IsThemeColor(colorString string) bool { func Darken(colorString string) (string, error) { if IsThemeColor(colorString) { - switch colorString[1] { - case '1': - return B1, nil - case '2': - return B1, nil - case '3': - return B2, nil - case '4': - return B3, nil - case '5': - return B4, nil - case '6': - return B5, nil - default: - return "", fmt.Errorf("darkening color \"%s\" is not yet supported", colorString) // TODO Add the rest of the colors so we can allow the user to specify theme colors too + switch { + case colorString[0] == 'B': + switch colorString[1] { + case '1', '2': + return B1, nil + case '3': + return B2, nil + case '4': + return B3, nil + case '5': + return B4, nil + case '6': + return B5, nil + } + + case colorString[0:2] == "AA": + switch colorString[2] { + case '2', '4': + return AA2, nil + case '5': + return AA4, nil + } + + case colorString[0:2] == "AB": + switch colorString[2] { + case '4', '5': + return AB4, nil + } + + case colorString[0] == 'N': + switch colorString[1] { + case '1', '2': + return N1, nil + case '3': + return N2, nil + case '4': + return N3, nil + case '5': + return N4, nil + case '6': + return N5, nil + case '7': + return N6, nil + } } + + return "", fmt.Errorf("invalid color \"%s\"", colorString) } return darkenCSS(colorString)