index.es.mjs 1.6 KB

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