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