index.cjs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var postcss = _interopDefault(require('postcss'));
  4. var parser = _interopDefault(require('postcss-values-parser'));
  5. const placeMatch = /^place-(content|items|self)/;
  6. var index = postcss.plugin('postcss-place', opts => {
  7. // prepare options
  8. const preserve = 'preserve' in Object(opts) ? Boolean(opts.prefix) : true;
  9. return root => {
  10. // walk each matching declaration
  11. root.walkDecls(placeMatch, decl => {
  12. // alignment
  13. const alignment = decl.prop.match(placeMatch)[1]; // value ast and child nodes
  14. const value = parser(decl.value).parse();
  15. const children = value.nodes[0].nodes; // new justify-[alignment] and align-[alignment] declarations
  16. const alignValue = children.length === 1 ? decl.value : String(children.slice(0, 1)).trim();
  17. const justifyValue = children.length === 1 ? decl.value : String(children.slice(1)).trim();
  18. decl.cloneBefore({
  19. prop: `align-${alignment}`,
  20. value: alignValue
  21. });
  22. decl.cloneBefore({
  23. prop: `justify-${alignment}`,
  24. value: justifyValue
  25. }); // conditionally remove place-[alignment]
  26. if (!preserve) {
  27. decl.remove();
  28. }
  29. });
  30. };
  31. });
  32. module.exports = index;
  33. //# sourceMappingURL=index.cjs.js.map