Skip to content

Commit 3affb4f

Browse files
authored
fix: divide, space, font-variation-settings (#199)
1 parent 8e339d1 commit 3affb4f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/removeUnsupported.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { writeFileSync } = require("fs");
2+
13
const remRE = /\d?\.?\d+\s*r?em/g;
24

35
function isSupportedProperty(prop, val = null) {
@@ -44,6 +46,10 @@ module.exports = (options = { debug: false }) => {
4446
mediaAtRule.remove();
4547
},
4648
},
49+
// Uncomment to debug the final output
50+
// OnceExit(rule) {
51+
// writeFileSync('./tailwind-output.css', rule.toString());
52+
// },
4753
Rule(rule) {
4854
// remove empty rules
4955
if (rule.nodes.length === 0) {
@@ -90,7 +96,14 @@ module.exports = (options = { debug: false }) => {
9096
);
9197
}
9298

93-
// replace space and divide selectors to use a simpler selector that works in ns
99+
// replace space and divide selectors to use a simpler selector that works in ns (v4 and newer)
100+
if (rule.selector.includes(":not(:last-child)")) {
101+
rule.selectors = rule.selectors.map((selector) => {
102+
return selector.replace(":not(:last-child)", "* + *");
103+
});
104+
}
105+
106+
// replace space and divide selectors to use a simpler selector that works in ns (older versions)
94107
if (rule.selector.includes(":not([hidden]) ~ :not([hidden])")) {
95108
rule.selectors = rule.selectors.map((selector) => {
96109
return selector.replace(":not([hidden]) ~ :not([hidden])", "* + *");
@@ -107,6 +120,16 @@ module.exports = (options = { debug: false }) => {
107120
}
108121
}
109122

123+
// tailvind v4 changed how the divide and space utilities work, now we need to set two variables called
124+
// --tw-divide-x-reverse and --tw-divide-y-reverse but for them to work we need to remove the variable
125+
// declarations from the divide and space utilities classes
126+
const broken = /--tw-(divide|space)-[xy]-reverse/g;
127+
128+
if (decl.prop?.match(broken) && decl.parent.selector?.match(/\.(divide|space)-[xy]/)) {
129+
return decl.remove();
130+
}
131+
132+
110133
// invalid with core 8.8+ at moment
111134
// Note: could be supported at somepoint
112135
if (decl.prop === "placeholder-color" && decl.value?.includes("color-mix")) {
@@ -226,6 +249,7 @@ const supportedProperties = {
226249
"font-size": true,
227250
"font-style": ["italic", "normal"],
228251
"font-weight": true,
252+
"font-variation-settings": true,
229253
height: true,
230254
"highlight-color": true,
231255
"horizontal-align": ["left", "center", "right", "stretch"],
@@ -271,6 +295,7 @@ const supportedProperties = {
271295
"text-shadow": true,
272296
"text-transform": ["none", "capitalize", "uppercase", "lowercase"],
273297
transform: true,
298+
rotate: true,
274299
"vertical-align": ["top", "center", "bottom", "stretch"],
275300
visibility: ["visible", "collapse"],
276301
width: true,

0 commit comments

Comments
 (0)