Skip to content

Commit 5b4b6cd

Browse files
committed
Add support for Tailwindcss v1.x
1 parent ddd3959 commit 5b4b6cd

File tree

4 files changed

+3844
-24
lines changed

4 files changed

+3844
-24
lines changed

index.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
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+
})
1436
}
1537
}

package.json

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,40 @@
22
"name": "tailwindcss-image-rendering",
33
"version": "0.1.0",
44
"description": "Image-rendering utilities for Tailwind CSS.",
5-
"main": "index.js",
6-
"repository": {
7-
"type": "git",
8-
"url": "git+https://github.com/hacknug/tailwindcss-image-rendering.git"
9-
},
105
"keywords": [
6+
"plugin",
117
"tailwind",
12-
"tailwindcss",
138
"tailwind css",
14-
"tailwindcss-plugin",
15-
"plugin"
9+
"tailwindcss",
10+
"tailwindcss-plugin"
1611
],
17-
"author": "Nestor Vera <[email protected]> (https://nestor.rip)",
18-
"license": "MIT",
12+
"homepage": "https://github.com/hacknug/tailwindcss-image-rendering#readme",
1913
"bugs": {
2014
"url": "https://github.com/hacknug/tailwindcss-image-rendering/issues"
2115
},
22-
"homepage": "https://github.com/hacknug/tailwindcss-image-rendering#readme"
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/hacknug/tailwindcss-image-rendering.git"
19+
},
20+
"license": "MIT",
21+
"author": {
22+
"name": "Nestor Vera",
23+
"email": "[email protected]",
24+
"url": "https://nestor.rip/"
25+
},
26+
"main": "index.js",
27+
"scripts": {
28+
"dev": "jest --watchAll",
29+
"test": "jest"
30+
},
31+
"dependencies": {
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"
40+
}
2341
}

0 commit comments

Comments
 (0)