-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (41 loc) · 1.67 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
var _ = require('lodash')
var flatten = require('flat')
const FLATTEN_CONFIG = { delimiter: '-', maxDepth: 2 }
const getName = name => name.split('-default').join('')
module.exports = function () {
return function ({
addUtilities, addComponents, addBase, addVariant,
e, prefix, theme, variants, config,
}) {
const buildObjectFromTheme = (themeKey, ...fallbackKeys) => {
const buildObject = ([ modifier, value ]) => [ modifier, { [themeKey]: value } ]
const getThemeSettings = (themeKey, fallbackKeys) => {
return theme(themeKey, false) || getThemeSettings([themeKey, ...fallbackKeys] = fallbackKeys)
}
const themeEntries = Object
.entries(flatten(getThemeSettings(themeKey, fallbackKeys), FLATTEN_CONFIG))
.map(entry => buildObject(entry))
return _.fromPairs(themeEntries)
}
const pluginUtilities = {
rendering: {
'auto': { imageRendering: 'auto' },
// 'smooth': { imageRendering: 'smooth' },
// 'high-quality': { imageRendering: 'high-quality' },
'crisp-edges': { imageRendering: 'crisp-edges' },
'pixelated': { imageRendering: 'pixelated' },
},
}
Object.entries(pluginUtilities)
.filter(([ modifier, values ]) => !_.isEmpty(values))
.forEach(([ modifier, values ]) => {
const className = _.kebabCase(modifier)
const variantName = Object.keys(Object.entries(values)[0][1])[0]
const utilities = flatten({ [`.${e(`${className}`)}`]: values }, FLATTEN_CONFIG)
addUtilities(
_.mapKeys(utilities, (value, key) => getName(key)),
variants(variantName, ['responsive'])
)
})
}
}