source: trip-planner-front/node_modules/postcss-minify-params/dist/index.js@ 6fe77af

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

primeNG components

  • Property mode set to 100644
File size: 4.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _browserslist = _interopRequireDefault(require("browserslist"));
9
10var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
11
12var _alphanumSort = _interopRequireDefault(require("alphanum-sort"));
13
14var _cssnanoUtils = require("cssnano-utils");
15
16function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
18function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22/**
23 * Return the greatest common divisor
24 * of two numbers.
25 */
26function gcd(a, b) {
27 return b ? gcd(b, a % b) : a;
28}
29
30function aspectRatio(a, b) {
31 const divisor = gcd(a, b);
32 return [a / divisor, b / divisor];
33}
34
35function split(args) {
36 return args.map(arg => (0, _postcssValueParser.stringify)(arg)).join('');
37}
38
39function removeNode(node) {
40 node.value = '';
41 node.type = 'word';
42}
43
44function sortAndDedupe(items) {
45 return (0, _alphanumSort.default)([...new Set(items)], {
46 insensitive: true
47 }).join();
48}
49
50function transform(legacy, rule) {
51 const ruleName = rule.name.toLowerCase(); // We should re-arrange parameters only for `@media` and `@supports` at-rules
52
53 if (!rule.params || !['media', 'supports'].includes(ruleName)) {
54 return;
55 }
56
57 const params = (0, _postcssValueParser.default)(rule.params);
58 params.walk((node, index) => {
59 if (node.type === 'div' || node.type === 'function') {
60 node.before = node.after = '';
61
62 if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3) {
63 const [a, b] = aspectRatio(node.nodes[2].value, node.nodes[4].value);
64 node.nodes[2].value = a;
65 node.nodes[4].value = b;
66 }
67 } else if (node.type === 'space') {
68 node.value = ' ';
69 } else {
70 const prevWord = params.nodes[index - 2];
71
72 if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) {
73 const nextWord = params.nodes[index + 2];
74
75 if (!legacy || nextWord) {
76 removeNode(node);
77 }
78
79 if (nextWord && nextWord.value.toLowerCase() === 'and') {
80 const nextSpace = params.nodes[index + 1];
81 const secondSpace = params.nodes[index + 3];
82 removeNode(nextWord);
83 removeNode(nextSpace);
84 removeNode(secondSpace);
85 }
86 }
87 }
88 }, true);
89 rule.params = sortAndDedupe((0, _cssnanoUtils.getArguments)(params).map(split));
90
91 if (!rule.params.length) {
92 rule.raws.afterName = '';
93 }
94}
95
96function hasAllBug(browser) {
97 return ~['ie 10', 'ie 11'].indexOf(browser);
98}
99
100function pluginCreator(options = {}) {
101 const browsers = (0, _browserslist.default)(null, {
102 stats: options.stats,
103 path: __dirname,
104 env: options.env
105 });
106 return {
107 postcssPlugin: 'postcss-minify-params',
108
109 OnceExit(css) {
110 css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
111 }
112
113 };
114}
115
116pluginCreator.postcss = true;
117var _default = pluginCreator;
118exports.default = _default;
119module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.