Skip to content

Commit 5078eff

Browse files
committed
Add support for Tailwind v1.x
1 parent 37d8789 commit 5078eff

File tree

5 files changed

+4014
-26
lines changed

5 files changed

+4014
-26
lines changed

index.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
1-
const _ = require('lodash')
1+
var _ = require('lodash')
2+
var flatten = require('flat')
23

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-
})
94

10-
const getName = (name) => name === 'default' ? '' : `-${name}`
5+
const FLATTEN_CONFIG = { delimiter: '-', maxDepth: 2 }
6+
const getName = name => name.split('-default').join('')
117

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-
}))
168

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))
2022

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+
})
2345
}
2446
}

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@
2424
"url": "https://nestor.rip/"
2525
},
2626
"main": "index.js",
27+
"scripts": {
28+
"dev": "jest --watchAll",
29+
"test": "jest"
30+
},
2731
"dependencies": {
28-
"lodash": "^4.17.10"
32+
"flat": "^4.1.0",
33+
"lodash": "^4.17.11"
34+
},
35+
"devDependencies": {
36+
"jest": "^24.8.0",
37+
"jest-matcher-css": "^1.0.3",
38+
"postcss": "^7.0.16",
39+
"tailwindcss": "^1.0.1"
2940
}
3041
}

0 commit comments

Comments
 (0)