padding.js 922 B

1234567891011121314151617181920212223242526272829303132
  1. var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
  2. function isNegative(value) {
  3. return value && value[1][0] == '-' && parseFloat(value[1]) < 0;
  4. }
  5. var plugin = {
  6. level1: {
  7. property: function padding(_rule, property, options) {
  8. var values = property.value;
  9. // remove multiple zeros
  10. if (values.length == 4 && values[0][1] === '0' && values[1][1] === '0' && values[2][1] === '0' && values[3][1] === '0') {
  11. property.value.splice(1);
  12. property.dirty = true;
  13. }
  14. // remove negative paddings
  15. if (options.level[OptimizationLevel.One].removeNegativePaddings
  16. && (
  17. isNegative(property.value[0])
  18. || isNegative(property.value[1])
  19. || isNegative(property.value[2])
  20. || isNegative(property.value[3])
  21. )) {
  22. property.unused = true;
  23. }
  24. }
  25. }
  26. };
  27. module.exports = plugin;