Skip to content

Commit

Permalink
remove css variable migration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-ershkov committed Dec 5, 2024
1 parent 32ff333 commit 813034c
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 183 deletions.
3 changes: 3 additions & 0 deletions packages/postcss-logical-fallback/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log - postcss-logical-fallback

## 1.1.0
Remove CSS variables support

## 1.0.3
Fix can't read filter of undefined

Expand Down
4 changes: 4 additions & 0 deletions packages/postcss-logical-fallback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Please note that the utility and functionality of this plugin may be limited whe
**WARNING**
Plugin is based on @supports at rule, so it has to be supported, see on [can i use](https://caniuse.com/css-featurequeries)

**WARNING**
Plugin doesn't migrates css properties with css variables due to impossibility of resolving how many values in css
variable and how to split them.

## Usage

**Step 1:** install plugin and postcss
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-logical-fallback/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-logical-fallback",
"version": "1.0.3",
"version": "1.1.0",
"description": "PostCSS plugin for logical fallback props",
"main": "index.js",
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import {Declaration} from "postcss";
import {parseCssValue} from "../utils";
import { Declaration } from 'postcss';
import { parseCssValue } from '../utils';
import { isCssVariable } from '../utils/is-css-variable';

const valueMap = {
ltr: {
start: 'left',
end: 'right'
},
rtl: {
start: 'right',
end: 'left'
}
}
ltr: {
start: 'left',
end: 'right',
},
rtl: {
start: 'right',
end: 'left',
},
};

export const processor = (decl: Declaration, dir = 'ltr') => {
const [start, end = start] = parseCssValue(decl.value)
if (isCssVariable(decl.value)) {
return;
}

decl.cloneBefore({
prop: valueMap[dir].start,
value: start
})
decl.cloneBefore({
prop: valueMap[dir].end,
value: end
})
const [start, end = start] = parseCssValue(decl.value);

decl.remove()
}
decl.cloneBefore({
prop: valueMap[dir].start,
value: start,
});
decl.cloneBefore({
prop: valueMap[dir].end,
value: end,
});

decl.remove();
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {Declaration} from "postcss";
import {parseCssValue} from "../utils";
import { Declaration } from 'postcss';
import { parseCssValue } from '../utils';
import { isCssVariable } from '../utils/is-css-variable';

export const processor = (decl: Declaration) => {
const { prop, value } = decl
const [start, end = start] = parseCssValue(value)
decl.cloneBefore({
prop: `${prop}-start`,
value: start,
})
decl.cloneBefore({
prop: `${prop}-end`,
value: end,
})
decl.remove()
}
const { prop, value } = decl;
if (isCssVariable(value)) {
return;
}

const [start, end = start] = parseCssValue(value);
decl.cloneBefore({
prop: `${prop}-start`,
value: start,
});
decl.cloneBefore({
prop: `${prop}-end`,
value: end,
});
decl.remove();
};
Loading

0 comments on commit 813034c

Please sign in to comment.