-
Notifications
You must be signed in to change notification settings - Fork 104
/
build.js
183 lines (139 loc) · 7.31 KB
/
build.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
function Build(settings, patterns) {
let resources = {};
resources.settings = settings;
resources.patterns = patterns;
resources.mixin = require('./system/mixin.js');
resources.media = require('./system/media.js');
resources.helpers = require('./system/helpers.js');
resources.size = require('./system/size.js');
resources.shift = require('./system/shift.js');
resources.styles = require('./system/styles.js');
resources.replaces = require('./system/replaces.js');
let base = require('./system/base.js');
let globalMediaCondition = settings.mobileFirst ? 'min-width' : 'max-width';
let str = '';
str += "{{var}}columns{{=}}" + resources.settings.columns + '{{;}}\n';
str += "{{var}}atom{{=}}(100% / {{var}}columns){{;}}\n";
str += '\n';
for (let name in resources.settings.breakPoints) {
str += "{{var}}break_" + name + '{{=}}' + resources.settings.breakPoints[name].width + "{{;}}\n";
}
str += '\n';
str += "{{var}}offset{{=}}" + resources.settings.offset + '{{;}}\n';
let last_offset = "{{var}}offset";
for (let name in resources.settings.breakPoints) {
let br = resources.settings.breakPoints[name];
if(br.offset !== undefined){
str += "{{var}}offset_" + name + '{{=}}' + br.offset + "{{;}}\n";
last_offset = "{{var}}offset_" + name;
}
else{
str += "{{var}}offset_" + name + '{{=}}' + last_offset + "{{;}}\n";
}
}
str += '\n';
str += "{{var}}offset_one_side{{=}}({{var}}offset / 2){{;}}\n";
for (let name in resources.settings.breakPoints) {
str += `{{var}}offset_${name}_one_side{{=}}({{var}}offset_${name} / 2){{;}}\n`;
}
str += '\n';
str += "{{var}}fields{{=}}" + resources.settings.container.fields + '{{;}}\n';
for (let name in resources.settings.breakPoints) {
let br = resources.settings.breakPoints[name];
if(br.fields !== undefined){
str += "{{var}}fields_" + name + '{{=}}' + br.fields + "{{;}}\n";
}
}
str += '\n';
str += (new base(resources)).render();
let size = new resources.size(resources, resources.settings.mixinNames.size);
str += size.render() + "\n\n";
for (let name in resources.settings.breakPoints) {
size = new resources.size(resources, resources.settings.mixinNames.size, name);
str += size.render() + "\n\n";
}
let shift = new resources.shift(resources, resources.settings.mixinNames.shift);
str += shift.render() + "\n\n";
for (let name in resources.settings.breakPoints) {
shift = new resources.shift(resources, resources.settings.mixinNames.shift, name);
str += shift.render() + "\n\n";
}
for (let name in resources.settings.breakPoints) {
let media = new resources.media("{{var}}break_" + name, globalMediaCondition, resources.settings.defaultMediaDevice);
let styles = "{{string-var}}name{{/string-var}}{{:}}{{var}}value{{;}}\n";
let mix = new resources.mixin(resources.patterns.mixin, name, '{{var}}name, {{var}}value', media.wrap(styles, 1));
str += mix.render(resources.settings.outputStyle) + "\n\n";
styles = "{{block-content-extract}}{{;}}\n";
mix = new resources.mixin(resources.patterns.mixin, name + '-block', '{{block-content-var}}', media.wrap(styles, 1));
str += mix.render(resources.settings.outputStyle) + "\n\n";
}
let fromMedia = new resources.media("{{var}}min_width", 'min-width', resources.settings.defaultMediaDevice);
let fromCommand = '{{block-content-extract}}{{;}}\n';
let from = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.from, '{{var}}min_width{{block-content-var-delimeter}}{{block-content-var}}', fromMedia.wrap(fromCommand, 1));
str += from.render();
str += "\n\n";
let toMedia = new resources.media("{{var}}max_width", 'max-width', resources.settings.defaultMediaDevice);
let toCommand = '{{block-content-extract}}{{;}}\n';
let to = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.to, '{{var}}max_width{{block-content-var-delimeter}}{{block-content-var}}', toMedia.wrap(toCommand, 1));
str += to.render();
str += "\n\n";
let fromTo = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.fromTo, '{{var}}min_width, {{var}}max_width{{block-content-var-delimeter}}{{block-content-var}}', resources.patterns.fromTo);
str += fromTo.render();
str += "\n\n";
/* user rows start */
let emptyMedia = new resources.media();
/* row */
let uRowCommands = resources.styles.objToStyles({
display: 'flex',
'flex-wrap': 'wrap',
'margin-left': '({{var}}offset / -2)',
'margin-right': '({{var}}offset / -2)'
}, 1);
let urow = new resources.mixin(resources.patterns.mixin,
resources.settings.mixinNames.uRowFlex,
'{{var}}offset',
emptyMedia.wrap(uRowCommands));
str += urow.render();
str += "\n\n";
/* col */
let uColCommands = resources.styles.objToStyles({
'box-sizing': 'border-box',
'word-wrap': 'break-word',
'margin-left': '({{var}}offset / 2)',
'margin-right': '({{var}}offset / 2)'
}, 1);
let ucol = new resources.mixin(resources.patterns.mixin,
resources.settings.mixinNames.uColumn,
'{{var}}offset',
emptyMedia.wrap(uColCommands));
str += ucol.render();
str += "\n\n";
/* size */
let uSizeCommands = resources.styles.objToStyles({
'width': '{{i}}calc(100% / {{string-var}}columns{{/string-var}} * {{string-var}}n{{/string-var}} - {{string-var}}offset{{/string-var}}){{/i}}'
}, 1);
let usize = new resources.mixin(resources.patterns.mixin,
resources.settings.mixinNames.uSize,
'{{var}}n, {{var}}columns, {{var}}offset',
emptyMedia.wrap(uSizeCommands));
str += usize.render();
str += "\n\n";
/* user rows end */
let reset = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.reset, '', resources.patterns.reset);
str += reset.render();
str += "\n\n";
let debug = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.debug, '{{var}}background, {{var}}outline', resources.patterns.debug);
str += debug.render();
str += "\n\n";
let clearfix = new resources.mixin(resources.patterns.mixin, resources.settings.mixinNames.clearfix, '', resources.patterns.clearfix);
str += clearfix.render();
let replaces = new resources.replaces(resources);
str = replaces.all(str, resources.settings.outputStyle);
str = replaces.fixLines(str);
return {
res: true,
grid: str,
type: resources.settings.outputStyle
};
}
module.exports = Build;