-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.js
221 lines (204 loc) · 6.18 KB
/
index.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
'use strict';
const fs = require('fs');
const path = require('path');
const color = require('color');
const yaml = require('js-yaml');
const filepaths = {
backgrounds: path.resolve(__dirname, 'backgrounds'),
gifs: path.resolve(__dirname, 'pokecursors')
};
const colorSchemes = {
types: path.resolve(__dirname, 'themes', 'types.yml'),
pokemon: path.resolve(__dirname, 'themes', 'pokemon.yml'),
trainers: path.resolve(__dirname, 'themes', 'trainers.yml')
};
function getUserOptions(configObj) {
return Object.assign({}, {
get pokemon() {
if (Array.isArray(configObj.pokemon)) {
return configObj.pokemon[Math.floor(Math.random() * configObj.pokemon.length)];
}
return configObj.pokemon || 'pikachu';
},
get exclude() {
const {exclude} = configObj;
if (!exclude) {
return [];
}
if (Array.isArray(exclude)) {
return exclude;
}
return [exclude];
},
get poketab() {
return (configObj.poketab || 'false') === 'true';
},
get unibody() {
return (configObj.unibody || 'true') !== 'false';
}
});
}
function getRandomTheme(category, exclude) {
const keys = Object.keys(category).filter(key => !exclude.includes(key));
if (keys.length > 0) {
const index = Math.floor(Math.random() * (keys.length));
const name = keys[index];
return [name, category[name]];
}
// All themes filtered out thus resolve to default
return ['pikachu', themes.pokemon.pikachu];
}
function getThemes() {
const themes = {};
Object.keys(colorSchemes).forEach(category => {
Object.assign(themes, yaml.safeLoad(fs.readFileSync(colorSchemes[category], 'utf8')));
});
return themes;
}
function getThemeColors(theme, exclude) {
const themes = getThemes();
const name = theme.trim().toLowerCase();
const excludedThemes = [...new Set(exclude)].map(x => x.trim().toLowerCase());
if (name === 'random') {
return getRandomTheme(themes.pokemon, excludedThemes);
}
if (Object.prototype.hasOwnProperty.call(themes, name)) {
// Choose a random theme from the given category -- i.e. `fire`
return getRandomTheme(themes[name], excludedThemes);
}
if (Object.prototype.hasOwnProperty.call(themes.pokemon, name)) {
// Return the requested pokemon theme -- i.e. `lapras`
return [name, themes.pokemon[name]];
}
// Got non-existent theme name thus resolve to default
return ['pikachu', themes.pokemon.pikachu];
}
function getMediaPaths(theme) {
const [imagePath, gifPath] = [[], []];
imagePath.push(...[path.join(filepaths.backgrounds, theme), '.png']);
gifPath.push(...[path.join(filepaths.gifs, theme), '.gif']);
if (process.platform === 'win32') {
return [imagePath, gifPath].map(item => item.join('').replace(/\\/g, '/'));
}
return [imagePath.join(''), gifPath.join('')];
}
exports.decorateConfig = config => {
// Get user options
const options = getUserOptions(config);
const [themeName, colors] = getThemeColors(options.pokemon, options.exclude);
const [imagePath, gifPath] = getMediaPaths(themeName);
// Set theme colors
const {primary, secondary, tertiary, unibody} = colors;
const background = options.unibody ? unibody : primary;
const selection = color(primary).alpha(0.3).string();
const transparent = color(secondary).alpha(0).string();
const header = color(background).isDark() ? '#FAFAFA' : '#010101';
const isSecondaryDark = color(secondary).isDark();
const activeTab = isSecondaryDark ? '#FAFAFA' : '#383A42';
const highlight = isSecondaryDark ? '#FFFFFF' : '#000000';
const secondHighlight = isSecondaryDark ? '#C7C7C7' : '#686868';
const tab = color(activeTab).darken(0.1);
// Set poketab
const tabContent = options.poketab ? gifPath : '';
const syntax = {
backgroundColor: transparent,
borderColor: background,
cursorColor: secondary,
foregroundColor: secondary,
selectionColor: selection,
colors: {
black: tertiary,
red: secondary,
green: tertiary,
yellow: secondary,
blue: secondary,
magenta: secondary,
cyan: secondary,
white: secondHighlight,
lightBlack: tertiary,
lightRed: secondary,
lightGreen: secondary,
lightYellow: secondary,
lightBlue: secondary,
lightMagenta: secondary,
lightCyan: secondary,
lightWhite: highlight
}
};
return Object.assign({}, config, syntax, {
termCSS: config.termCSS || '',
css: `
${config.css || ''}
.terms_terms {
background: url("file://${imagePath}") center;
background-size: cover;
}
.header_shape, .header_appTitle {
color: ${header};
}
.header_header, .header_windowHeader {
background-color: ${background} !important;
}
.hyper_main {
background-color: ${background};
}
.tab_textActive .tab_textInner::before {
content: url("file://${tabContent}");
position: absolute;
right: 0;
top: -4px;
}
.tabs_nav .tabs_list {
border-bottom: 0;
}
.tabs_nav .tabs_title,
.tabs_nav .tabs_list .tab_tab {
color: ${secondary};
border: 0;
}
.tab_icon {
color: ${background};
width: 15px;
height: 15px;
}
.tab_icon:hover {
background-color: ${background};
}
.tab_shape {
color: ${secondary};
width: 7px;
height: 7px;
}
.tab_shape:hover {
color: ${secondary};
}
.tab_active {
background-color: ${activeTab};
}
.tabs_nav .tabs_list .tab_tab:not(.tab_active) {
background-color: ${tab};
}
.tabs_nav .tabs_list {
color: ${background};
}
.tab_tab::before {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4px;
background-color: ${secondary};
transform: scaleX(0);
transition: none;
}
.tab_tab.tab_active::before {
transform: scaleX(1);
transition: all 400ms cubic-bezier(0.0, 0.0, 0.2, 1)
}
.terms_terms .terms_termGroup .splitpane_panes .splitpane_divider {
background-color: ${secondary} !important;
}
`
});
};