-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpluginApi.js
51 lines (43 loc) · 1.66 KB
/
pluginApi.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
const fromPairs = require('lodash/fromPairs')
const toPairs = require('lodash/toPairs')
const merge = require('lodash/merge')
const isEmpty = require('lodash/isEmpty')
const _forEach = require('lodash/forEach')
const has = require('lodash/has')
const { setVariable, setDarkMediaVariable, setComponent, build, darkBuild, flattenOptions } = require('./utils')
const variables = (variables, options) => {
let variableList = {}
let data = build(options, variables)
_forEach(data, (value, key) => merge(variableList, setVariable(key, fromPairs(value))))
return variableList
}
const darkVariables = (variables, options, darkMode = 'media') => {
let variableList = {}
if (darkMode === 'class' || darkMode === 'media') {
if (!has(options, 'darkSelector')) {
options.darkSelector = '.dark'
}
let data = darkBuild(options, darkMode, variables)
_forEach(data, (value, key) =>
merge(
variableList,
darkMode === 'media' ? setDarkMediaVariable(key, fromPairs(value)) : setVariable(key, fromPairs(value))
)
)
}
return variableList
}
const getComponents = (selector, components) => {
let componentList = {}
selector = isEmpty(selector) ? '' : selector
toPairs(flattenOptions(components)).forEach(([key, config]) => {
const modifier = key === 'DEFAULT' ? '' : isEmpty(selector) ? `${key}` : `-${key}`
toPairs(config)
.filter(([, options]) => !isEmpty(options))
.forEach(([subKey, options]) => merge(componentList, setComponent(selector, modifier, options)))
})
return componentList
}
module.exports.getComponents = getComponents
module.exports.variables = variables
module.exports.darkVariables = darkVariables