1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 |
43x
43x
2155x
2616x
2155x
2730x
334x
2396x
1203x
1193x
1x
1x
1192x
2155x
1241x
1241x
1241x
2395x
2395x
7412x
828x
828x
593x
828x
960x
6584x
7412x
2395x
2155x
8943x
8943x
3329x
5614x
5614x
4426x
1188x
1188x
1188x
1214x
1214x
1214x
1188x
1188x
2155x
| // to use a style var, for example:
//
// import { style } from 'app/styles';
//
// const myStyle = {
// backgroundColor: '@colors.altBackground',
// }
// return (<MyComponent style={style(myStyle)}/>);
//
// These are used to map theme colors and other style tweaks in the various
// editor plugins.
const styleVars = {
colors: {
added: 'green',
altBackground: 'whitesmoke',
altForeground: '#333333',
background: '#FEFEFE',
boxShadow: 'rgba(0, 0, 0, 0.2)',
blobColor: '#696969',
deleted: 'red',
disabledText: '#e0e0e0',
error: 'red',
leftRevColor: 'red',
linkText: 'blue',
inputBackground: '#FEFEFE',
inputForeground: '#333333',
modified: 'orange',
panelBorder: 'whitesmoke',
rightRevColor: 'green',
selectable: 'lightskyblue',
selected: 'lightskyblue',
text: '#333333',
},
margins: {
small: 3,
medium: 7,
large: 15,
pageTop: 20,
pageLeft: 20,
pageBottom: 20,
pageRight: 20,
},
};
// NOTE: the colors above are used below as string values preceded with '@' so they
// can be intepolated at runtime and allow changes for theme-ing
const globalStyles = {
background: {
background: '@colors.background',
},
panel: {
background: '@colors.background',
borderRadius: 3,
color: '@colors.text',
marginRight: '@margins.medium+px',
padding: '@margins.medium+px',
},
altPanel: {
_extends: 'panel',
background: '@colors.altBackground',
color: '@colors.altForeground',
},
borderedPanel: {
_extends: 'panel',
border: '1px solid @colors.panelBorder',
},
fill: {
position: 'relative',
height: '100%',
width: '100%',
},
popup: {
_extends: 'panel',
position: 'absolute',
zIndex: 1,
boxShadow: '0 4px 8px 0 @colors.boxShadow, 0 6px 20px 0 @colors.boxShadow',
},
block: {
display: 'block',
marginBottom: '@margins.medium+px',
},
inline: {
display: 'inline-block',
},
inlineBlock: {
display: 'inline-block',
marginRight: '@margins.medium+px',
},
card: {
_extends: 'panel',
borderRadius: 7,
marginBottom: '@margins.medium+px',
marginRight: '@margins.medium+px',
},
flexColumn: {
display: 'flex',
flexDirection: 'column',
},
flexRow: {
display: 'flex',
flexDirection: 'row',
},
flexGrow: {
display: 'flex',
flexGrow: 1,
},
normalText: {
fontSize: 12,
lineHeight: 1.35,
fontWeight: 'normal',
color: '@colors.text',
},
bigText: {
_extends: 'normalText',
fontSize: 18,
},
largerText: {
_extends: 'normalText',
fontSize: 14,
},
smallerText: {
_extends: 'normalText',
fontSize: 11,
},
boldText: {
fontWeight: 'bold',
},
disabledText: {
color: '@colors.disabledText',
},
headerText: {
_extends: ['normalText', 'boldText'],
marginBottom: '@margins.large+px',
marginRight: '@margins.large+px',
},
h1Text: {
_extends: 'headerText',
fontSize: 22,
marginRight: '@margins.large+px',
},
h2Text: {
_extends: 'headerText',
fontSize: 18,
},
h3Text: {
_extends: 'headerText',
fontSize: 14,
},
h4Text: {
_extends: 'headerText',
fontSize: 12,
marginBottom: '@margins.medium+px',
marginRight: '@margins.medium+px',
},
h5Text: {
_extends: 'headerText',
fontSize: 14,
fontWeight: 'normal',
marginBottom: '@margins.medium+px',
marginRight: '@margins.medium+px',
},
errorText: {
_extends: 'largerText',
color: '@colors.error',
},
linesAdded: {
color: 'green',
},
linesDeleted: {
color: 'red',
},
selectable: {
border: `1px solid @colors.selectable`,
borderRadius: 3,
cursor: 'pointer',
userSelect: 'none',
},
selected: {
_extends: 'selectable',
background: '@colors.selected',
},
link: {
color: '@colors.linkText',
cursor: 'pointer',
textDecoration: 'underline',
},
linkHover: {
_extends: 'link',
textDecoration: 'underline',
},
menuDivider: {
borderBottom: `2px solid @colors.altBackground`,
marginBottom: '@margins.medium+px',
},
};
export function style(...styles) {
const styleOut = {};
const flattenedStyles = styles.reduce((acc, val) => acc.concat(val), []);
for (const specifiedStyle of flattenedStyles) {
if (!specifiedStyle) {
continue;
}
if (typeof specifiedStyle === 'object') {
Object.assign(styleOut, processExtends(specifiedStyle));
} else {
if (!globalStyles.hasOwnProperty(specifiedStyle)) {
debugger;
console.warn(`git-temporal: unknown style requested ${specifiedStyle}`);
} else {
Object.assign(styleOut, processExtends(globalStyles[specifiedStyle]));
}
}
}
return interpolateStyleVars(styleOut);
}
export function getStyleVar(groupName, varName) {
// @ts-ignore
const globalOverrides = window && window.GT_STYLE_VARS;
const group =
(globalOverrides && globalOverrides[groupName]) || styleVars[groupName];
// group could be specified in globalOverrides but not include the var itself
return group.hasOwnProperty(varName)
? group[varName]
: styleVars[groupName][varName];
}
function processExtends(styleObject) {
const styleOut = {};
for (const propertyName in styleObject) {
if (propertyName === '_extends') {
let extendedStyles = styleObject[propertyName];
if (!Array.isArray(extendedStyles)) {
extendedStyles = [extendedStyles];
}
for (const extendedStyle of extendedStyles) {
Object.assign(styleOut, style(extendedStyle));
}
} else {
styleOut[propertyName] = styleObject[propertyName];
}
// @ts-ignore
delete styleOut._extends;
}
return styleOut;
}
function interpolateStyleVars(styleObject) {
for (const key in styleObject) {
const value = styleObject[key];
if (!(typeof value === 'string' || value instanceof String)) {
continue;
}
const matches = value.match(/\@[^\s\.]*\.[^\s]*/g);
if (!matches || matches.length <= 0) {
continue;
}
const regex = /\@([^\s\.]*)\.([^\s\+]*)\+?/;
let newValue = value;
for (const match of matches) {
const [_matchedValue, styleVarsGroup, styleVar] = match.match(regex);
const interpolated = getStyleVar(styleVarsGroup, styleVar);
if (interpolated) {
newValue = newValue.replace(regex, interpolated);
}
}
styleObject[key] = newValue;
}
return styleObject;
}
|