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.7 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = function (nodes, opts) {
  6. let i, max, node, familyStart, family;
  7. let hasSize = false;
  8. for (i = 0, max = nodes.length; i < max; i += 1) {
  9. node = nodes[i];
  10. if (node.type === 'word') {
  11. if (hasSize) {
  12. continue;
  13. }
  14. const value = node.value.toLowerCase();
  15. if (value === 'normal' || ~_keywords2.default.style.indexOf(value) || ~_keywords2.default.variant.indexOf(value) || ~_keywords2.default.stretch.indexOf(value)) {
  16. familyStart = i;
  17. } else if (~_keywords2.default.weight.indexOf(value)) {
  18. node.value = (0, _minifyWeight2.default)(value);
  19. familyStart = i;
  20. } else if (~_keywords2.default.size.indexOf(value) || (0, _postcssValueParser.unit)(value)) {
  21. familyStart = i;
  22. hasSize = true;
  23. }
  24. } else if (node.type === 'div' && node.value === '/') {
  25. familyStart = i + 1;
  26. break;
  27. }
  28. }
  29. familyStart += 2;
  30. family = (0, _minifyFamily2.default)(nodes.slice(familyStart), opts);
  31. return nodes.slice(0, familyStart).concat(family);
  32. };
  33. var _postcssValueParser = require('postcss-value-parser');
  34. var _keywords = require('./keywords');
  35. var _keywords2 = _interopRequireDefault(_keywords);
  36. var _minifyFamily = require('./minify-family');
  37. var _minifyFamily2 = _interopRequireDefault(_minifyFamily);
  38. var _minifyWeight = require('./minify-weight');
  39. var _minifyWeight2 = _interopRequireDefault(_minifyWeight);
  40. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  41. ;
  42. module.exports = exports['default'];