list.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. /**
  5. * Contains helpers for safely splitting lists of CSS values,
  6. * preserving parentheses and quotes.
  7. *
  8. * @example
  9. * const list = postcss.list
  10. *
  11. * @namespace list
  12. */
  13. var list = {
  14. split: function split(string, separators, last) {
  15. var array = [];
  16. var current = '';
  17. var split = false;
  18. var func = 0;
  19. var quote = false;
  20. var escape = false;
  21. for (var i = 0; i < string.length; i++) {
  22. var letter = string[i];
  23. if (quote) {
  24. if (escape) {
  25. escape = false;
  26. } else if (letter === '\\') {
  27. escape = true;
  28. } else if (letter === quote) {
  29. quote = false;
  30. }
  31. } else if (letter === '"' || letter === '\'') {
  32. quote = letter;
  33. } else if (letter === '(') {
  34. func += 1;
  35. } else if (letter === ')') {
  36. if (func > 0) func -= 1;
  37. } else if (func === 0) {
  38. if (separators.indexOf(letter) !== -1) split = true;
  39. }
  40. if (split) {
  41. if (current !== '') array.push(current.trim());
  42. current = '';
  43. split = false;
  44. } else {
  45. current += letter;
  46. }
  47. }
  48. if (last || current !== '') array.push(current.trim());
  49. return array;
  50. },
  51. /**
  52. * Safely splits space-separated values (such as those for `background`,
  53. * `border-radius`, and other shorthand properties).
  54. *
  55. * @param {string} string Space-separated values.
  56. *
  57. * @return {string[]} Split values.
  58. *
  59. * @example
  60. * postcss.list.space('1px calc(10% + 1px)') //=> ['1px', 'calc(10% + 1px)']
  61. */
  62. space: function space(string) {
  63. var spaces = [' ', '\n', '\t'];
  64. return list.split(string, spaces);
  65. },
  66. /**
  67. * Safely splits comma-separated values (such as those for `transition-*`
  68. * and `background` properties).
  69. *
  70. * @param {string} string Comma-separated values.
  71. *
  72. * @return {string[]} Split values.
  73. *
  74. * @example
  75. * postcss.list.comma('black, linear-gradient(white, black)')
  76. * //=> ['black', 'linear-gradient(white, black)']
  77. */
  78. comma: function comma(string) {
  79. return list.split(string, [','], true);
  80. }
  81. };
  82. var _default = list;
  83. exports.default = _default;
  84. module.exports = exports.default;
  85. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxpc3QuZXM2Il0sIm5hbWVzIjpbImxpc3QiLCJzcGxpdCIsInN0cmluZyIsInNlcGFyYXRvcnMiLCJsYXN0IiwiYXJyYXkiLCJjdXJyZW50IiwiZnVuYyIsInF1b3RlIiwiZXNjYXBlIiwiaSIsImxlbmd0aCIsImxldHRlciIsImluZGV4T2YiLCJwdXNoIiwidHJpbSIsInNwYWNlIiwic3BhY2VzIiwiY29tbWEiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUE7Ozs7Ozs7OztBQVNBLElBQUlBLElBQUksR0FBRztBQUVUQyxFQUFBQSxLQUZTLGlCQUVGQyxNQUZFLEVBRU1DLFVBRk4sRUFFa0JDLElBRmxCLEVBRXdCO0FBQy9CLFFBQUlDLEtBQUssR0FBRyxFQUFaO0FBQ0EsUUFBSUMsT0FBTyxHQUFHLEVBQWQ7QUFDQSxRQUFJTCxLQUFLLEdBQUcsS0FBWjtBQUVBLFFBQUlNLElBQUksR0FBRyxDQUFYO0FBQ0EsUUFBSUMsS0FBSyxHQUFHLEtBQVo7QUFDQSxRQUFJQyxNQUFNLEdBQUcsS0FBYjs7QUFFQSxTQUFLLElBQUlDLENBQUMsR0FBRyxDQUFiLEVBQWdCQSxDQUFDLEdBQUdSLE1BQU0sQ0FBQ1MsTUFBM0IsRUFBbUNELENBQUMsRUFBcEMsRUFBd0M7QUFDdEMsVUFBSUUsTUFBTSxHQUFHVixNQUFNLENBQUNRLENBQUQsQ0FBbkI7O0FBRUEsVUFBSUYsS0FBSixFQUFXO0FBQ1QsWUFBSUMsTUFBSixFQUFZO0FBQ1ZBLFVBQUFBLE1BQU0sR0FBRyxLQUFUO0FBQ0QsU0FGRCxNQUVPLElBQUlHLE1BQU0sS0FBSyxJQUFmLEVBQ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krKykge1xuICAgICAgbGV0IGxldHRlciA9IHN0cmluZ1tpXVxuXG4gICAgICBpZiAocXVvdGUpIHtcbiAgICAgICAgaWYgKGVzY2FwZSkge1xuICAgICAgICAgIGVzY2FwZSA9IGZhbHNlXG4gICAgICAgIH0gZWxzZSBpZiAobGV0dGVyID09PSAnXFxcXCcpIHtcbiAgICAgICAgICBlc2NhcGUgPSB0cnVlXG4gICAgICAgIH0gZWxzZSBpZiAobGV0dGVyID09PSBxdW90ZSkge1xuICAgICAgICAgIHF1b3RlID0gZmFsc2VcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChsZXR0ZXIgPT09ICdcIicgfHwgbGV0dGVyID09PSAnXFwnJykge1xuICAgICAgICBxdW90ZSA9IGxldHRlclxuICAgICAgfSBlbHNlIGlmIChsZXR0ZXIgPT09ICcoJykge1xuICAgICAgICBmdW5jICs9IDFcbiAgICAgIH0gZWxzZSBpZiAobGV0dGVyID09PSAnKScpIHtcbiAgICAgICAgaWYgKGZ1bmMgPiAwKSBmdW5jIC09IDFcbiAgICAgIH0gZWxzZSBpZiAoZnVuYyA9PT0gMCkge1xuICAgICAgICBpZiAoc2VwYXJhdG9ycy5pbmRleE9mKGxldHRlcikgIT09IC0xKSBzcGxpdCA9IHRydWVcbiAgICAgIH1cblxuICAgICAgaWYgKHNwbGl0KSB7XG4gICAgICAgIGlmIChjdXJyZW50ICE9PSAnJykgYXJyYXkucHVzaChjdXJyZW50LnRyaW0oKSlcbiAgICAgICAgY3VycmVudCA9ICcnXG4gICAgICAgIHNwbGl0ID0gZmFsc2VcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGN1cnJlbnQgKz0gbGV0dGVyXG4gICAgICB9XG4gICAgfVxuXG4gICAgaWYgKGxhc3QgfHwgY3VycmVudCAhPT0gJycpIGFycmF5LnB1c2goY3VycmVudC50cmltKCkpXG4gICAgcmV0dXJuIGFycmF5XG4gIH0sXG5cbiAgLyoqXG4gICAqIFNhZmVseSBzcGxpdH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