source: trip-planner-front/node_modules/postcss-normalize-whitespace/dist/index.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12const atrule = 'atrule';
13const decl = 'decl';
14const rule = 'rule';
15
16function reduceCalcWhitespaces(node) {
17 if (node.type === 'space') {
18 node.value = ' ';
19 } else if (node.type === 'function') {
20 if (!['var', 'env', 'constant'].includes(node.value.toLowerCase())) {
21 node.before = node.after = '';
22 }
23 }
24}
25
26function reduceWhitespaces(node) {
27 if (node.type === 'space') {
28 node.value = ' ';
29 } else if (node.type === 'div') {
30 node.before = node.after = '';
31 } else if (node.type === 'function') {
32 if (!['var', 'env', 'constant'].includes(node.value.toLowerCase())) {
33 node.before = node.after = '';
34 }
35
36 if (node.value.toLowerCase() === 'calc') {
37 _postcssValueParser.default.walk(node.nodes, reduceCalcWhitespaces);
38
39 return false;
40 }
41 }
42}
43
44function pluginCreator() {
45 return {
46 postcssPlugin: 'postcss-normalize-whitespace',
47
48 OnceExit(css) {
49 const cache = {};
50 css.walk(node => {
51 const {
52 type
53 } = node;
54
55 if (~[decl, rule, atrule].indexOf(type) && node.raws.before) {
56 node.raws.before = node.raws.before.replace(/\s/g, '');
57 }
58
59 if (type === decl) {
60 // Ensure that !important values do not have any excess whitespace
61 if (node.important) {
62 node.raws.important = '!important';
63 } // Remove whitespaces around ie 9 hack
64
65
66 node.value = node.value.replace(/\s*(\\9)\s*/, '$1');
67 const value = node.value;
68
69 if (cache[value]) {
70 node.value = cache[value];
71 } else {
72 const parsed = (0, _postcssValueParser.default)(node.value);
73 const result = parsed.walk(reduceWhitespaces).toString(); // Trim whitespace inside functions & dividers
74
75 node.value = result;
76 cache[value] = result;
77 } // Remove extra semicolons and whitespace before the declaration
78
79
80 if (node.raws.before) {
81 const prev = node.prev();
82
83 if (prev && prev.type !== rule) {
84 node.raws.before = node.raws.before.replace(/;/g, '');
85 }
86 }
87
88 node.raws.between = ':';
89 node.raws.semicolon = false;
90 } else if (type === rule || type === atrule) {
91 node.raws.between = node.raws.after = '';
92 node.raws.semicolon = false;
93 }
94 }); // Remove final newline
95
96 css.raws.after = '';
97 }
98
99 };
100}
101
102pluginCreator.postcss = true;
103var _default = pluginCreator;
104exports.default = _default;
105module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.