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.

64 lines
1.6 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = parseWsc;
  6. var _postcss = require('postcss');
  7. var _validateWsc = require('./validateWsc');
  8. const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i;
  9. const varRE = /(^.*var)(.*\(.*--.*\))(.*)/i;
  10. const varPreserveCase = p => `${p[1].toLowerCase()}${p[2]}${p[3].toLowerCase()}`;
  11. const toLower = v => {
  12. const match = varRE.exec(v);
  13. return match ? varPreserveCase(match) : v.toLowerCase();
  14. };
  15. function parseWsc(value) {
  16. if (none.test(value)) {
  17. return ['medium', 'none', 'currentcolor'];
  18. }
  19. let width, style, color;
  20. const values = _postcss.list.space(value);
  21. if (values.length > 1 && (0, _validateWsc.isStyle)(values[1]) && values[0].toLowerCase() === 'none') {
  22. values.unshift();
  23. width = '0';
  24. }
  25. const unknown = [];
  26. values.forEach(v => {
  27. if ((0, _validateWsc.isStyle)(v)) {
  28. style = toLower(v);
  29. } else if ((0, _validateWsc.isWidth)(v)) {
  30. width = toLower(v);
  31. } else if ((0, _validateWsc.isColor)(v)) {
  32. color = toLower(v);
  33. } else {
  34. unknown.push(v);
  35. }
  36. });
  37. if (unknown.length) {
  38. if (!width && style && color) {
  39. width = unknown.pop();
  40. }
  41. if (width && !style && color) {
  42. style = unknown.pop();
  43. }
  44. if (width && style && !color) {
  45. color = unknown.pop();
  46. }
  47. }
  48. return [width, style, color];
  49. }
  50. module.exports = exports['default'];