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.

45 lines
1.2 KiB

4 years ago
  1. module.exports = function compressFont(node) {
  2. var list = node.children;
  3. list.eachRight(function(node, item) {
  4. if (node.type === 'Identifier') {
  5. if (node.name === 'bold') {
  6. item.data = {
  7. type: 'Number',
  8. loc: node.loc,
  9. value: '700'
  10. };
  11. } else if (node.name === 'normal') {
  12. var prev = item.prev;
  13. if (prev && prev.data.type === 'Operator' && prev.data.value === '/') {
  14. this.remove(prev);
  15. }
  16. this.remove(item);
  17. } else if (node.name === 'medium') {
  18. var next = item.next;
  19. if (!next || next.data.type !== 'Operator') {
  20. this.remove(item);
  21. }
  22. }
  23. }
  24. });
  25. // remove redundant spaces
  26. list.each(function(node, item) {
  27. if (node.type === 'WhiteSpace') {
  28. if (!item.prev || !item.next || item.next.data.type === 'WhiteSpace') {
  29. this.remove(item);
  30. }
  31. }
  32. });
  33. if (list.isEmpty()) {
  34. list.insert(list.createItem({
  35. type: 'Identifier',
  36. name: 'normal'
  37. }));
  38. }
  39. };