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.

50 lines
1.6 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = normalizeBorder;
  6. var _postcssValueParser = require('postcss-value-parser');
  7. // border: <line-width> || <line-style> || <color>
  8. // outline: <outline-color> || <outline-style> || <outline-width>
  9. const borderWidths = ['thin', 'medium', 'thick'];
  10. const borderStyles = ['none', 'auto', // only in outline-style
  11. 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
  12. function normalizeBorder(border) {
  13. const order = { width: '', style: '', color: '' };
  14. border.walk(node => {
  15. const { type, value } = node;
  16. if (type === 'word') {
  17. if (~borderStyles.indexOf(value.toLowerCase())) {
  18. order.style = value;
  19. return false;
  20. }
  21. if (~borderWidths.indexOf(value.toLowerCase()) || (0, _postcssValueParser.unit)(value.toLowerCase())) {
  22. if (order.width !== '') {
  23. order.width = `${order.width} ${value}`;
  24. return false;
  25. }
  26. order.width = value;
  27. return false;
  28. }
  29. order.color = value;
  30. return false;
  31. }
  32. if (type === 'function') {
  33. if (value.toLowerCase() === 'calc') {
  34. order.width = (0, _postcssValueParser.stringify)(node);
  35. } else {
  36. order.color = (0, _postcssValueParser.stringify)(node);
  37. }
  38. return false;
  39. }
  40. });
  41. return `${order.width} ${order.style} ${order.color}`.trim();
  42. };
  43. module.exports = exports['default'];