|
1 |
| -module.exports = function (variants) { |
2 |
| - return function ({ addUtilities }) { |
3 |
| - addUtilities( |
4 |
| - { |
5 |
| - // Image Rendering |
6 |
| - 'rendering-auto': { imageRendering: 'auto' }, |
7 |
| - // 'rendering-smooth': { imageRendering: 'smooth' }, |
8 |
| - // 'rendering-high-quality': { imageRendering: 'high-quality' }, |
9 |
| - 'rendering-crisp-edges': { imageRendering: 'crisp-edges' }, |
10 |
| - 'rendering-pixelated': { imageRendering: 'pixelated' }, |
11 |
| - }, |
12 |
| - variants |
13 |
| - ) |
| 1 | +var _ = require('lodash') |
| 2 | +var flatten = require('flat') |
| 3 | + |
| 4 | +module.exports = function () { |
| 5 | + return function ({ |
| 6 | + addUtilities, addComponents, addBase, addVariant, |
| 7 | + e, prefix, theme, variants, config, |
| 8 | + }) { |
| 9 | + const buildObjectFromTheme = themeKey => { |
| 10 | + const buildObject = ([ modifier, value ]) => [ modifier, { [themeKey]: value } ] |
| 11 | + const themeEntries = Object.entries(theme(themeKey, {})).map(entry => buildObject(entry)) |
| 12 | + return _.fromPairs(themeEntries) |
| 13 | + } |
| 14 | + |
| 15 | + const pluginUtilities = { |
| 16 | + rendering: { |
| 17 | + 'auto': { imageRendering: 'auto' }, |
| 18 | + // 'smooth': { imageRendering: 'smooth' }, |
| 19 | + // 'high-quality': { imageRendering: 'high-quality' }, |
| 20 | + 'crisp-edges': { imageRendering: 'crisp-edges' }, |
| 21 | + 'pixelated': { imageRendering: 'pixelated' }, |
| 22 | + }, |
| 23 | + } |
| 24 | + |
| 25 | + Object.entries(pluginUtilities) |
| 26 | + .filter(([ modifier, values ]) => !_.isEmpty(values)) |
| 27 | + .forEach(([ modifier, values ]) => { |
| 28 | + const variantName = Object.keys(Object.entries(values)[0][1])[0] |
| 29 | + const utilities = flatten( |
| 30 | + { [`.${e(`bg-${modifier}`)}`]: values }, |
| 31 | + { delimiter: '-', maxDepth: 2 }, |
| 32 | + ) |
| 33 | + |
| 34 | + addUtilities(utilities, variants(variantName, ['responsive'])) |
| 35 | + }) |
14 | 36 | }
|
15 | 37 | }
|
0 commit comments