index.cjs.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. function _toArray(arr) {
  5. return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
  6. }
  7. function _arrayWithHoles(arr) {
  8. if (Array.isArray(arr)) return arr;
  9. }
  10. function _iterableToArray(iter) {
  11. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  12. }
  13. function _nonIterableRest() {
  14. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  15. }
  16. const space = postcss.list.space; // overflow shorthand property matcher
  17. const overflowPropertyRegExp = /^overflow$/i;
  18. var index = postcss.plugin('postcss-overflow-shorthand', opts => {
  19. const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
  20. return root => {
  21. // for each overflow declaration
  22. root.walkDecls(overflowPropertyRegExp, decl => {
  23. // split the declaration values
  24. const _space = space(decl.value),
  25. _space2 = _toArray(_space),
  26. overflowX = _space2[0],
  27. overflowY = _space2[1],
  28. invalidatingValues = _space2.slice(2); // if there are two values, but no invalidating values
  29. if (overflowY && !invalidatingValues.length) {
  30. // insert the overflow-* longhand declarations
  31. decl.cloneBefore({
  32. prop: `${decl.prop}-x`,
  33. value: overflowX
  34. });
  35. decl.cloneBefore({
  36. prop: `${decl.prop}-y`,
  37. value: overflowY
  38. }); // conditionally remove the original declaration
  39. if (!preserve) {
  40. decl.remove();
  41. }
  42. }
  43. });
  44. };
  45. });
  46. module.exports = index;
  47. //# sourceMappingURL=index.cjs.js.map