|
1 | | -module.exports = function(variants) { |
2 | | - return function({ addUtilities }) { |
3 | | - addUtilities( |
4 | | - { |
5 | | - // Mix Blend Mode |
6 | | - '.blend-normal': { mixBlendMode: 'normal' }, |
7 | | - '.blend-multiply': { mixBlendMode: 'multiply' }, |
8 | | - '.blend-screen': { mixBlendMode: 'screen' }, |
9 | | - '.blend-overlay': { mixBlendMode: 'overlay' }, |
10 | | - '.blend-darken': { mixBlendMode: 'darken' }, |
11 | | - '.blend-lighten': { mixBlendMode: 'lighten' }, |
12 | | - '.blend-color-dodge': { mixBlendMode: 'color-dodge' }, |
13 | | - '.blend-color-burn': { mixBlendMode: 'color-burn' }, |
14 | | - '.blend-hard-light': { mixBlendMode: 'hard-light' }, |
15 | | - '.blend-soft-light': { mixBlendMode: 'soft-light' }, |
16 | | - '.blend-difference': { mixBlendMode: 'difference' }, |
17 | | - '.blend-exclusion': { mixBlendMode: 'exclusion' }, |
18 | | - '.blend-hue': { mixBlendMode: 'hue' }, |
19 | | - '.blend-saturation': { mixBlendMode: 'saturation' }, |
20 | | - '.blend-color': { mixBlendMode: 'color' }, |
21 | | - '.blend-luminosity': { mixBlendMode: 'luminosity' }, |
| 1 | +var _ = require('lodash') |
| 2 | +var flatten = require('flat') |
22 | 3 |
|
23 | | - // Background Blend Mode |
24 | | - '.bg-blend-normal': { backgroundBlendMode: 'normal' }, |
25 | | - '.bg-blend-multiply': { backgroundBlendMode: 'multiply' }, |
26 | | - '.bg-blend-screen': { backgroundBlendMode: 'screen' }, |
27 | | - '.bg-blend-overlay': { backgroundBlendMode: 'overlay' }, |
28 | | - '.bg-blend-darken': { backgroundBlendMode: 'darken' }, |
29 | | - '.bg-blend-lighten': { backgroundBlendMode: 'lighten' }, |
30 | | - '.bg-blend-color-dodge': { backgroundBlendMode: 'color-dodge' }, |
31 | | - '.bg-blend-color-burn': { backgroundBlendMode: 'color-burn' }, |
32 | | - '.bg-blend-hard-light': { backgroundBlendMode: 'hard-light' }, |
33 | | - '.bg-blend-soft-light': { backgroundBlendMode: 'soft-light' }, |
34 | | - '.bg-blend-difference': { backgroundBlendMode: 'difference' }, |
35 | | - '.bg-blend-exclusion': { backgroundBlendMode: 'exclusion' }, |
36 | | - '.bg-blend-hue': { backgroundBlendMode: 'hue' }, |
37 | | - '.bg-blend-saturation': { backgroundBlendMode: 'saturation' }, |
38 | | - '.bg-blend-color': { backgroundBlendMode: 'color' }, |
39 | | - '.bg-blend-luminosity': { backgroundBlendMode: 'luminosity' }, |
| 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 | + } |
40 | 14 |
|
41 | | - // Isolate |
42 | | - '.isolate': { isolation: 'isolate' }, |
43 | | - '.isolate-none': { isolation: 'auto' }, |
44 | | - }, |
45 | | - variants |
46 | | - ) |
| 15 | + const pluginUtilities = { |
| 16 | + 'blend': { |
| 17 | + 'normal': { mixBlendMode: 'normal' }, |
| 18 | + 'multiply': { mixBlendMode: 'multiply' }, |
| 19 | + 'screen': { mixBlendMode: 'screen' }, |
| 20 | + 'overlay': { mixBlendMode: 'overlay' }, |
| 21 | + 'darken': { mixBlendMode: 'darken' }, |
| 22 | + 'lighten': { mixBlendMode: 'lighten' }, |
| 23 | + 'color-dodge': { mixBlendMode: 'color-dodge' }, |
| 24 | + 'color-burn': { mixBlendMode: 'color-burn' }, |
| 25 | + 'hard-light': { mixBlendMode: 'hard-light' }, |
| 26 | + 'soft-light': { mixBlendMode: 'soft-light' }, |
| 27 | + 'difference': { mixBlendMode: 'difference' }, |
| 28 | + 'exclusion': { mixBlendMode: 'exclusion' }, |
| 29 | + 'hue': { mixBlendMode: 'hue' }, |
| 30 | + 'saturation': { mixBlendMode: 'saturation' }, |
| 31 | + 'color': { mixBlendMode: 'color' }, |
| 32 | + 'luminosity': { mixBlendMode: 'luminosity' }, |
| 33 | + }, |
| 34 | + 'bg-blend': { |
| 35 | + 'normal': { backgroundBlendMode: 'normal' }, |
| 36 | + 'multiply': { backgroundBlendMode: 'multiply' }, |
| 37 | + 'screen': { backgroundBlendMode: 'screen' }, |
| 38 | + 'overlay': { backgroundBlendMode: 'overlay' }, |
| 39 | + 'darken': { backgroundBlendMode: 'darken' }, |
| 40 | + 'lighten': { backgroundBlendMode: 'lighten' }, |
| 41 | + 'color-dodge': { backgroundBlendMode: 'color-dodge' }, |
| 42 | + 'color-burn': { backgroundBlendMode: 'color-burn' }, |
| 43 | + 'hard-light': { backgroundBlendMode: 'hard-light' }, |
| 44 | + 'soft-light': { backgroundBlendMode: 'soft-light' }, |
| 45 | + 'difference': { backgroundBlendMode: 'difference' }, |
| 46 | + 'exclusion': { backgroundBlendMode: 'exclusion' }, |
| 47 | + 'hue': { backgroundBlendMode: 'hue' }, |
| 48 | + 'saturation': { backgroundBlendMode: 'saturation' }, |
| 49 | + 'color': { backgroundBlendMode: 'color' }, |
| 50 | + 'luminosity': { backgroundBlendMode: 'luminosity' }, |
| 51 | + }, |
| 52 | + 'isolation': { |
| 53 | + 'isolate': { isolation: 'isolate' }, |
| 54 | + 'auto': { isolation: 'auto' }, |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + Object.entries(pluginUtilities) |
| 59 | + .filter(([ modifier, values ]) => !_.isEmpty(values)) |
| 60 | + .forEach(([ modifier, values ]) => { |
| 61 | + const variantName = Object.keys(Object.entries(values)[0][1])[0] |
| 62 | + const utilities = flatten( |
| 63 | + { [`.${e(`${modifier}`)}`]: values }, |
| 64 | + { delimiter: '-', maxDepth: 2 }, |
| 65 | + ) |
| 66 | + |
| 67 | + addUtilities(utilities, variants(variantName, ['responsive'])) |
| 68 | + }) |
47 | 69 | } |
48 | 70 | } |
0 commit comments