-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.js
79 lines (70 loc) · 1.91 KB
/
utils.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
var x = require('xtend')
var gr8util = require('gr8-util')
var objectValues = require('object-values')
module.exports = gr8utils
var defaults = {
spacing: [0, 1, 2, 3, 4],
fontSize: [1, 1.2, 1.6, 2.4, 3.2, 6.4],
lineHeight: [1, 1.5],
size: [0, 100],
viewport: [50, 100],
zIndex: [0, 1, 2, 3, 4],
flexOrder: [0, 1, 2, 3, 4],
opacity: [0, 25, 50, 75, 100],
aspectRatio: [25, 50, 75, 100],
textColumn: [1, 2, 3, 4],
unit: 'rem'
}
var utils = {
column: require('./utils/column'),
margin: require('./utils/margin'),
padding: require('./utils/padding'),
opacity: require('./utils/opacity'),
background: require('./utils/background'),
flex: require('./utils/flex'),
display: require('./utils/display'),
float: require('./utils/float'),
overflow: require('./utils/overflow'),
positioning: require('./utils/positioning'),
size: require('./utils/size'),
typography: require('./utils/type'),
miscellaneous: require('./utils/misc'),
development: require('./utils/dev')
}
function gr8utils (options) {
return generate(filter(utils, options.exclude), options)
}
// public
gr8utils.defaults = defaults
gr8utils.utils = utils
gr8utils.generate = generate
function filter (utils, keys) {
if (!Array.isArray(keys)) return utils
var allKeys = Object.keys(utils)
keys.forEach(function (key) {
var isMatch = allKeys.indexOf(key) >= 0
if (isMatch) {
delete utils[key]
}
})
return utils
}
function generate (utils, options) {
options = x(defaults, options)
return objectValues(utils).map(function (util) {
return generateEach(objectValues(util), options)
}).join('\n')
}
function generateEach (utils, options) {
return utils.map(function (util) {
if (typeof util === 'function') {
util = util(options)
}
if (typeof util === 'string') {
return util
} else {
util.selector = options.selector
return gr8util(util)
}
}).join('\n')
}