...
1
2
3 package d2themes
4
5 import (
6 "oss.terrastruct.com/d2/d2target"
7 "oss.terrastruct.com/d2/lib/color"
8 )
9
10 type Theme struct {
11 ID int64 `json:"id"`
12 Name string `json:"name"`
13 Colors ColorPalette `json:"colors"`
14
15 SpecialRules SpecialRules `json:"specialRules,omitempty"`
16 }
17
18 type SpecialRules struct {
19 Mono bool `json:"mono"`
20 NoCornerRadius bool `json:"noCornerRadius"`
21 OuterContainerDoubleBorder bool `json:"outerContainerDoubleBorder"`
22 ContainerDots bool `json:"containerDots"`
23 CapsLock bool `json:"capsLock"`
24
25 AllPaper bool `json:"allPaper"`
26 }
27
28 func (t *Theme) IsDark() bool {
29 return t.ID >= 200 && t.ID < 300
30 }
31
32 func (t *Theme) ApplyOverrides(overrides *d2target.ThemeOverrides) {
33 if overrides == nil {
34 return
35 }
36
37 if overrides.B1 != nil {
38 t.Colors.B1 = *overrides.B1
39 }
40 if overrides.B2 != nil {
41 t.Colors.B2 = *overrides.B2
42 }
43 if overrides.B3 != nil {
44 t.Colors.B3 = *overrides.B3
45 }
46 if overrides.B4 != nil {
47 t.Colors.B4 = *overrides.B4
48 }
49 if overrides.B5 != nil {
50 t.Colors.B5 = *overrides.B5
51 }
52 if overrides.B5 != nil {
53 t.Colors.B5 = *overrides.B5
54 }
55 if overrides.B6 != nil {
56 t.Colors.B6 = *overrides.B6
57 }
58 if overrides.AA2 != nil {
59 t.Colors.AA2 = *overrides.AA2
60 }
61 if overrides.AA4 != nil {
62 t.Colors.AA4 = *overrides.AA4
63 }
64 if overrides.AA5 != nil {
65 t.Colors.AA5 = *overrides.AA5
66 }
67 if overrides.AB4 != nil {
68 t.Colors.AB4 = *overrides.AB4
69 }
70 if overrides.AB5 != nil {
71 t.Colors.AB5 = *overrides.AB5
72 }
73 if overrides.N1 != nil {
74 t.Colors.Neutrals.N1 = *overrides.N1
75 }
76 if overrides.N2 != nil {
77 t.Colors.Neutrals.N2 = *overrides.N2
78 }
79 if overrides.N3 != nil {
80 t.Colors.Neutrals.N3 = *overrides.N3
81 }
82 if overrides.N4 != nil {
83 t.Colors.Neutrals.N4 = *overrides.N4
84 }
85 if overrides.N5 != nil {
86 t.Colors.Neutrals.N5 = *overrides.N5
87 }
88 if overrides.N6 != nil {
89 t.Colors.Neutrals.N6 = *overrides.N6
90 }
91 if overrides.N7 != nil {
92 t.Colors.Neutrals.N7 = *overrides.N7
93 }
94 }
95
96 type Neutral struct {
97 N1 string `json:"n1"`
98 N2 string `json:"n2"`
99 N3 string `json:"n3"`
100 N4 string `json:"n4"`
101 N5 string `json:"n5"`
102 N6 string `json:"n6"`
103 N7 string `json:"n7"`
104 }
105
106 type ColorPalette struct {
107 Neutrals Neutral `json:"neutrals"`
108
109
110 B1 string `json:"b1"`
111 B2 string `json:"b2"`
112 B3 string `json:"b3"`
113 B4 string `json:"b4"`
114 B5 string `json:"b5"`
115 B6 string `json:"b6"`
116
117
118 AA2 string `json:"aa2"`
119 AA4 string `json:"aa4"`
120 AA5 string `json:"aa5"`
121
122
123 AB4 string `json:"ab4"`
124 AB5 string `json:"ab5"`
125 }
126
127 var CoolNeutral = Neutral{
128 N1: "#0A0F25",
129 N2: "#676C7E",
130 N3: "#9499AB",
131 N4: "#CFD2DD",
132 N5: "#DEE1EB",
133 N6: "#EEF1F8",
134 N7: "#FFFFFF",
135 }
136
137 var WarmNeutral = Neutral{
138 N1: "#170206",
139 N2: "#535152",
140 N3: "#787777",
141 N4: "#CCCACA",
142 N5: "#DFDCDC",
143 N6: "#ECEBEB",
144 N7: "#FFFFFF",
145 }
146
147 var DarkNeutral = Neutral{
148 N1: "#F4F6FA",
149 N2: "#BBBEC9",
150 N3: "#868A96",
151 N4: "#676D7D",
152 N5: "#3A3D49",
153 N6: "#191C28",
154 N7: "#000410",
155 }
156
157 var DarkMauveNeutral = Neutral{
158 N1: "#CDD6F4",
159 N2: "#BAC2DE",
160 N3: "#A6ADC8",
161 N4: "#585B70",
162 N5: "#45475A",
163 N6: "#313244",
164 N7: "#1E1E2E",
165 }
166
167 func ResolveThemeColor(theme Theme, code string) string {
168 if !color.IsThemeColor(code) {
169 return code
170 }
171 switch code {
172 case "N1":
173 return theme.Colors.Neutrals.N1
174 case "N2":
175 return theme.Colors.Neutrals.N2
176 case "N3":
177 return theme.Colors.Neutrals.N3
178 case "N4":
179 return theme.Colors.Neutrals.N4
180 case "N5":
181 return theme.Colors.Neutrals.N5
182 case "N6":
183 return theme.Colors.Neutrals.N6
184 case "N7":
185 return theme.Colors.Neutrals.N7
186 case "B1":
187 return theme.Colors.B1
188 case "B2":
189 return theme.Colors.B2
190 case "B3":
191 return theme.Colors.B3
192 case "B4":
193 return theme.Colors.B4
194 case "B5":
195 return theme.Colors.B5
196 case "B6":
197 return theme.Colors.B6
198 case "AA2":
199 return theme.Colors.AA2
200 case "AA4":
201 return theme.Colors.AA4
202 case "AA5":
203 return theme.Colors.AA5
204 case "AB4":
205 return theme.Colors.AB4
206 case "AB5":
207 return theme.Colors.AB5
208 default:
209 return ""
210 }
211 }
212
View as plain text