Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import postcss from 'postcss';
|
---|
2 | import parser from 'postcss-values-parser';
|
---|
3 |
|
---|
4 | const placeMatch = /^place-(content|items|self)/;
|
---|
5 | var index = postcss.plugin('postcss-place', opts => {
|
---|
6 | // prepare options
|
---|
7 | const preserve = 'preserve' in Object(opts) ? Boolean(opts.prefix) : true;
|
---|
8 | return root => {
|
---|
9 | // walk each matching declaration
|
---|
10 | root.walkDecls(placeMatch, decl => {
|
---|
11 | // alignment
|
---|
12 | const alignment = decl.prop.match(placeMatch)[1]; // value ast and child nodes
|
---|
13 |
|
---|
14 | const value = parser(decl.value).parse();
|
---|
15 | const children = value.nodes[0].nodes; // new justify-[alignment] and align-[alignment] declarations
|
---|
16 |
|
---|
17 | const alignValue = children.length === 1 ? decl.value : String(children.slice(0, 1)).trim();
|
---|
18 | const justifyValue = children.length === 1 ? decl.value : String(children.slice(1)).trim();
|
---|
19 | decl.cloneBefore({
|
---|
20 | prop: `align-${alignment}`,
|
---|
21 | value: alignValue
|
---|
22 | });
|
---|
23 | decl.cloneBefore({
|
---|
24 | prop: `justify-${alignment}`,
|
---|
25 | value: justifyValue
|
---|
26 | }); // conditionally remove place-[alignment]
|
---|
27 |
|
---|
28 | if (!preserve) {
|
---|
29 | decl.remove();
|
---|
30 | }
|
---|
31 | });
|
---|
32 | };
|
---|
33 | });
|
---|
34 |
|
---|
35 | export default index;
|
---|
36 | //# sourceMappingURL=index.es.mjs.map
|
---|
Note:
See
TracBrowser
for help on using the repository browser.