/
theme.js
380 lines (238 loc) · 8.64 KB
/
theme.js
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
'use strict';
import EventEmitterMixin from 'event-emitter-mixin';
import Color from 'color';
export class Theme extends EventEmitterMixin() {
constructor(customAttributes = {}) {
super();
if (typeof customAttributes === 'function') {
customAttributes = customAttributes(this);
}
this.customAttributes = customAttributes;
for (const name of Object.keys(customAttributes)) {
if (!(name in this)) {
const descriptor = {};
def(this, name, descriptor);
Object.defineProperty(this, name, descriptor);
}
}
}
// --- Base colors ---
// Material Design Blue 500
@def primaryColor = '#2196F3';
// Material Design Red A200
@def accentColor = '#FF5252';
@def backgroundColor = '#FFF';
@def bodyColor = this.backgroundColor; // DEPRECATED
@def inverseBackgroundColor = '#000';
@def overlayBackgroundColor = '#000';
@def borderColor = 'rgba(0,0,0,.12)';
@def inverseBorderColor = 'rgba(255,255,255,.88)';
@def
darkPrimaryColor = Color(this.primaryColor)
.darken(0.3)
.string();
@def
lightPrimaryColor = Color(this.primaryColor)
.lighten(0.6)
.string();
@def
darkAccentColor = Color(this.accentColor)
.darken(0.4)
.string();
@def
lightAccentColor = Color(this.accentColor)
.lighten(0.3)
.string();
@def
altBackgroundColor = Color(this.backgroundColor)
.darken(0.03)
.string();
@def altBodyColor = this.altBackgroundColor; // DEPRECATED
@def
altBorderColor = Color(this.borderColor)
.opaquer(0.3)
.string();
@def
altInverseBorderColor = Color(this.inverseBorderColor)
.opaquer(1)
.string();
@def baseTextColor = '#000';
@def
textColor = Color(this.baseTextColor)
.alpha(0.87)
.string();
@def primaryTextColor = this.textColor; // DEPRECATED
@def
altTextColor = Color(this.baseTextColor)
.alpha(0.54)
.string();
@def secondaryTextColor = this.altTextColor; // DEPRECATED
@def
mutedTextColor = Color(this.baseTextColor)
.alpha(0.38)
.string();
@def baseInverseTextColor = '#FFF';
@def
inverseTextColor = Color(this.baseInverseTextColor)
.alpha(1)
.string();
@def
inverseAltTextColor = Color(this.baseInverseTextColor)
.alpha(0.7)
.string();
@def
inverseMutedTextColor = Color(this.baseInverseTextColor)
.alpha(0.5)
.string();
// Material Design Red 500
@def errorColor = '#F44336';
// Material Design Orange 500
@def warningColor = '#FF9800';
// --- Links ---
@def linkColor = this.accentColor;
@def linkDecoration = 'none';
@def hoveredLinkColor = this.darkAccentColor;
@def hoveredLinkDecoration = 'underline';
// --- Typography ---
@def
sansSerifFontFamily =
'-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen, Ubuntu, Cantarell, \'Fira Sans\', \'Droid Sans\', \'Helvetica Neue\', Arial, sans-serif';
@def serifFontFamily = 'Georgia, \'Times New Roman\', Times, serif';
@def monospaceFontFamily = 'Menlo, Monaco, Consolas, \'Liberation Mono\', \'Courier New\', monospace';
@def rootFontSize = '16px';
@def baseFontFamily = this.sansSerifFontFamily;
@def baseFontSize = '1rem';
// http://www.modularscale.com/?1&em&1.2&web&text
@def modularScaleRatio = 1.2;
modularScale(value, base = this.baseFontSize, ratio = this.modularScaleRatio) {
const multiplier = Math.pow(ratio, value);
const number = parseFloat(base);
const unit = String(base).slice(String(number).length);
return number * multiplier + unit;
}
// 1.44
@def baseLineHeight = this.modularScale(2, 1);
// 1.2
@def smallLineHeight = this.modularScale(1, 1);
// '.833rem'
@def smallFontSize = this.modularScale(-1);
// '1.2rem'
@def largeFontSize = this.modularScale(1);
@def strongFontWeight = 'bold';
@def headingsMarginBottom = '1rem';
@def headingsFontFamily = 'inherit';
@def headingsFontWeight = this.strongFontWeight;
@def headingsLineHeight = this.smallLineHeight;
@def headingsColor = 'inherit';
// '2.488rem'
@def h1FontSize = this.modularScale(5);
// '2.074rem'
@def h2FontSize = this.modularScale(4);
// '1.728rem'
@def h3FontSize = this.modularScale(3);
// '1.44rem'
@def h4FontSize = this.modularScale(2);
// '1.2rem'
@def h5FontSize = this.modularScale(1);
// '1rem'
@def h6FontSize = this.modularScale(0);
// --- Borders ---
@def borderWidth = '1px';
@def borderRadius = '.25rem';
@def smallBorderRadius = '.2rem';
@def largeBorderRadius = '.3rem';
// --- Tables ---
@def tableBackgroundColor = 'transparent';
@def tableCellPadding = '.75rem';
// --- Code ---
@def codeColor = this.darkPrimaryColor;
@def codeBackgroundColor = this.altBackgroundColor;
@def preColor = this.altTextColor;
@def preBackgroundColor = undefined;
// --- Buttons ---
@def buttonFontWeight = 'normal';
@def buttonLineHeight = this.smallLineHeight;
@def buttonXPadding = '1rem';
@def buttonYPadding = '.5rem';
@def smallButtonXPadding = '.5rem';
@def smallButtonYPadding = '.25rem';
@def largeButtonXPadding = '1.25rem';
@def largeButtonYPadding = '.75rem';
@def buttonTextColor = this.textColor;
@def buttonBackgroundColor = this.backgroundColor;
@def buttonBorderColor = this.borderColor;
@def hoveredButtonBackgroundColor = this.altBackgroundColor;
@def hoveredButtonBorderColor = this.altBorderColor;
@def primaryButtonTextColor = this.inverseTextColor;
@def primaryButtonBackgroundColor = this.primaryColor;
@def primaryButtonBorderColor = this.primaryButtonBackgroundColor;
@def hoveredPrimaryButtonBackgroundColor = this.darkPrimaryColor;
@def hoveredPrimaryButtonBorderColor = this.hoveredPrimaryButtonBackgroundColor;
@def accentButtonTextColor = this.inverseTextColor;
@def accentButtonBackgroundColor = this.accentColor;
@def accentButtonBorderColor = this.accentButtonBackgroundColor;
@def hoveredAccentButtonBackgroundColor = this.darkAccentColor;
@def hoveredAccentButtonBorderColor = this.hoveredAccentButtonBackgroundColor;
@def inverseButtonTextColor = this.inverseTextColor;
@def inverseButtonBackgroundColor = this.inverseBackgroundColor;
@def inverseButtonBorderColor = this.inverseBorderColor;
@def hoveredInverseButtonBackgroundColor = this.inverseBackgroundColor;
@def hoveredInverseButtonBorderColor = this.altInverseBorderColor;
// --- Inputs ---
@def inputLineHeight = this.smallLineHeight;
@def inputTextColor = this.textColor;
@def inputBackgroundColor = this.backgroundColor;
@def inputBorderWidth = this.borderWidth;
@def inputBorderColor = this.borderColor;
@def inputPlaceholderColor = this.mutedTextColor;
@def focusedInputBorderColor = this.primaryColor;
@def disabledInputBackgroundColor = this.altBackgroundColor;
@def inverseInputTextColor = this.inverseTextColor;
@def inverseInputBackgroundColor = this.inverseBackgroundColor;
@def inverseInputBorderColor = this.inverseBorderColor;
@def inverseInputPlaceholderColor = this.mutedTextColor; // TODO
@def focusedInverseInputBorderColor = this.primaryColor; // TODO
@def disabledInverseInputBackgroundColor = this.inverseInputBackgroundColor; // TODO
@def inputXPadding = '.625rem';
@def inputYPadding = '.5rem';
@def smallInputXPadding = '.375rem';
@def smallInputYPadding = '.25rem';
@def largeInputXPadding = '.875rem';
@def largeInputYPadding = '.75rem';
// --- Other ---
@def disabledCursor = 'not-allowed';
// --- Breakpoints ---
@def smallBreakpoint = '640px';
@def smallBreakpointMinusOne = parseInt(this.smallBreakpoint, 10) - 1 + 'px';
@def smallBreakpointPlusOne = parseInt(this.smallBreakpoint, 10) + 1 + 'px';
@def mediumBreakpoint = '1024px';
@def mediumBreakpointMinusOne = parseInt(this.mediumBreakpoint, 10) - 1 + 'px';
@def mediumBreakpointPlusOne = parseInt(this.mediumBreakpoint, 10) + 1 + 'px';
@def largeBreakpoint = '1440px';
@def largeBreakpointMinusOne = parseInt(this.largeBreakpoint, 10) - 1 + 'px';
@def largeBreakpointPlusOne = parseInt(this.largeBreakpoint, 10) + 1 + 'px';
}
function def(target, name, descriptor) {
const initializer = descriptor.initializer;
delete descriptor.initializer;
delete descriptor.writable;
descriptor.get = function () {
if (
this.customAttributes &&
Object.prototype.hasOwnProperty.call(this.customAttributes, name)
) {
let value = this.customAttributes[name];
if (typeof value === 'function') {
value = value(this);
}
return value;
}
return initializer.call(this);
};
descriptor.set = function (value) {
this.customAttributes[name] = value;
this.emit('didChange');
return value;
};
}
export default Theme;