index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _postcss = require("postcss");
  6. var _postcss2 = _interopRequireDefault(_postcss);
  7. var _postcssValueParser = require("postcss-value-parser");
  8. var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
  9. var _cssnanoUtilGetMatch = require("cssnano-util-get-match");
  10. var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
  11. var _map = require("./lib/map");
  12. var _map2 = _interopRequireDefault(_map);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
  15. function evenValues(list, index) {
  16. return index % 2 === 0;
  17. }
  18. exports.default = _postcss2.default.plugin("postcss-normalize-display-values", () => {
  19. return css => {
  20. const cache = {};
  21. css.walkDecls(/display/i, decl => {
  22. const value = decl.value;
  23. if (cache[value]) {
  24. decl.value = cache[value];
  25. return;
  26. }
  27. const { nodes } = (0, _postcssValueParser2.default)(value);
  28. if (nodes.length === 1) {
  29. cache[value] = value;
  30. return;
  31. }
  32. const match = getMatch(nodes.filter(evenValues).map(n => n.value.toLowerCase()));
  33. if (!match) {
  34. cache[value] = value;
  35. return;
  36. }
  37. const result = match;
  38. decl.value = result;
  39. cache[value] = result;
  40. });
  41. };
  42. });
  43. module.exports = exports["default"];