|
1 |
| -const _ = require('lodash') |
| 1 | +var _ = require('lodash') |
| 2 | +var flatten = require('flat') |
2 | 3 |
|
3 |
| -module.exports = function (options = {}) { |
4 |
| - return function ({ addUtilities, config, e }) { |
5 |
| - let { colors, widths, variants } = _.defaults(options, { |
6 |
| - colors: config('borderColors'), |
7 |
| - widths: config('borderWidths'), |
8 |
| - }) |
9 | 4 |
|
10 |
| - const getName = (name) => name === 'default' ? '' : `-${name}` |
| 5 | +const FLATTEN_CONFIG = { delimiter: '-', maxDepth: 2 } |
| 6 | +const getName = name => name.split('-default').join('') |
11 | 7 |
|
12 |
| - colors = _.map(colors, (color, name) => ({ |
13 |
| - [`.${e(`text-fill${getName(name)}`)}`]: { '-webkit-text-fill-color': color }, |
14 |
| - [`.${e(`text-stroke${getName(name)}`)}`]: { '-webkit-text-stroke-color': color }, |
15 |
| - })) |
16 | 8 |
|
17 |
| - widths = _.map(widths, (width, name) => ({ |
18 |
| - [`.${e(`text-stroke${getName(name)}`)}`]: { '-webkit-text-stroke-width': width }, |
19 |
| - })) |
| 9 | +module.exports = function () { |
| 10 | + return function ({ |
| 11 | + addUtilities, addComponents, addBase, addVariant, |
| 12 | + e, prefix, theme, variants, config, |
| 13 | + }) { |
| 14 | + const buildObjectFromTheme = (themeKey, ...fallbackKeys) => { |
| 15 | + const buildObject = ([ modifier, value ]) => [ modifier, { [themeKey]: value } ] |
| 16 | + const getThemeSettings = (themeKey, fallbackKeys) => { |
| 17 | + return theme(themeKey, false) || getThemeSettings([themeKey, ...fallbackKeys] = fallbackKeys) |
| 18 | + } |
| 19 | + const themeEntries = Object |
| 20 | + .entries(flatten(getThemeSettings(themeKey, fallbackKeys), FLATTEN_CONFIG)) |
| 21 | + .map(entry => buildObject(entry)) |
20 | 22 |
|
21 |
| - addUtilities(colors, variants) |
22 |
| - addUtilities(widths, variants) |
| 23 | + return _.fromPairs(themeEntries) |
| 24 | + } |
| 25 | + |
| 26 | + const pluginUtilities = { |
| 27 | + textFillColor: buildObjectFromTheme('textFillColor', 'borderColor'), |
| 28 | + textStrokeColor: buildObjectFromTheme('textStrokeColor', 'borderColor'), |
| 29 | + textStrokeWidth: buildObjectFromTheme('textStrokeWidth', 'borderWidth'), |
| 30 | + // paintOrder: 'https://developer.mozilla.org/en-US/docs/Web/CSS/paint-order', |
| 31 | + } |
| 32 | + |
| 33 | + Object.entries(pluginUtilities) |
| 34 | + .filter(([ modifier, values ]) => !_.isEmpty(values)) |
| 35 | + .forEach(([ modifier, values ]) => { |
| 36 | + const className = _.kebabCase(modifier).split('-').reverse().slice(1).reverse().join('-') |
| 37 | + const variantName = Object.keys(Object.entries(values)[0][1])[0] |
| 38 | + const utilities = flatten({ [`.${e(`${className}`)}`]: values }, FLATTEN_CONFIG) |
| 39 | + |
| 40 | + addUtilities( |
| 41 | + _.mapKeys(utilities, (value, key) => getName(key)), |
| 42 | + variants(variantName, ['responsive']) |
| 43 | + ) |
| 44 | + }) |
23 | 45 | }
|
24 | 46 | }
|
0 commit comments