You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

4 years ago
  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 _minifyWeight = require('./lib/minify-weight');
  10. var _minifyWeight2 = _interopRequireDefault(_minifyWeight);
  11. var _minifyFamily = require('./lib/minify-family');
  12. var _minifyFamily2 = _interopRequireDefault(_minifyFamily);
  13. var _minifyFont = require('./lib/minify-font');
  14. var _minifyFont2 = _interopRequireDefault(_minifyFont);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. function transform(opts, decl) {
  17. let tree;
  18. let prop = decl.prop.toLowerCase();
  19. if (prop === 'font-weight') {
  20. decl.value = (0, _minifyWeight2.default)(decl.value);
  21. } else if (prop === 'font-family') {
  22. tree = (0, _postcssValueParser2.default)(decl.value);
  23. tree.nodes = (0, _minifyFamily2.default)(tree.nodes, opts);
  24. decl.value = tree.toString();
  25. } else if (prop === 'font') {
  26. tree = (0, _postcssValueParser2.default)(decl.value);
  27. tree.nodes = (0, _minifyFont2.default)(tree.nodes, opts);
  28. decl.value = tree.toString();
  29. }
  30. }
  31. exports.default = _postcss2.default.plugin('postcss-minify-font-values', opts => {
  32. opts = Object.assign({}, {
  33. removeAfterKeyword: false,
  34. removeDuplicates: true,
  35. removeQuotes: true
  36. }, opts);
  37. return css => css.walkDecls(/font/i, transform.bind(null, opts));
  38. });
  39. module.exports = exports['default'];