source: trip-planner-front/node_modules/postcss-normalize-url/dist/index.js@ 76712b2

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

primeNG components

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _path = _interopRequireDefault(require("path"));
9
10var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
12var _normalizeUrl = _interopRequireDefault(require("normalize-url"));
13
14var _isAbsoluteUrl = _interopRequireDefault(require("is-absolute-url"));
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18const multiline = /\\[\r\n]/; // eslint-disable-next-line no-useless-escape
19
20const escapeChars = /([\s\(\)"'])/g;
21
22function convert(url, options) {
23 if ((0, _isAbsoluteUrl.default)(url) || url.startsWith('//')) {
24 let normalizedURL = null;
25
26 try {
27 normalizedURL = (0, _normalizeUrl.default)(url, options);
28 } catch (e) {
29 normalizedURL = url;
30 }
31
32 return normalizedURL;
33 } // `path.normalize` always returns backslashes on Windows, need replace in `/`
34
35
36 return _path.default.normalize(url).replace(new RegExp('\\' + _path.default.sep, 'g'), '/');
37}
38
39function transformNamespace(rule) {
40 rule.params = (0, _postcssValueParser.default)(rule.params).walk(node => {
41 if (node.type === 'function' && node.value.toLowerCase() === 'url' && node.nodes.length) {
42 node.type = 'string';
43 node.quote = node.nodes[0].quote || '"';
44 node.value = node.nodes[0].value;
45 }
46
47 if (node.type === 'string') {
48 node.value = node.value.trim();
49 }
50
51 return false;
52 }).toString();
53}
54
55function transformDecl(decl, opts) {
56 decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
57 if (node.type !== 'function' || node.value.toLowerCase() !== 'url') {
58 return false;
59 }
60
61 node.before = node.after = '';
62
63 if (!node.nodes.length) {
64 return false;
65 }
66
67 let url = node.nodes[0];
68 let escaped;
69 url.value = url.value.trim().replace(multiline, ''); // Skip empty URLs
70 // Empty URL function equals request to current stylesheet where it is declared
71
72 if (url.value.length === 0) {
73 url.quote = '';
74 return false;
75 }
76
77 if (/^data:(.*)?,/i.test(url.value)) {
78 return false;
79 }
80
81 if (!/^.+-extension:\//i.test(url.value)) {
82 url.value = convert(url.value, opts);
83 }
84
85 if (escapeChars.test(url.value) && url.type === 'string') {
86 escaped = url.value.replace(escapeChars, '\\$1');
87
88 if (escaped.length < url.value.length + 2) {
89 url.value = escaped;
90 url.type = 'word';
91 }
92 } else {
93 url.type = 'word';
94 }
95
96 return false;
97 }).toString();
98}
99
100function pluginCreator(opts) {
101 opts = Object.assign({}, {
102 normalizeProtocol: false,
[e29cc2e]103 sortQueryParameters: false,
[6a3a178]104 stripHash: false,
105 stripWWW: false,
106 stripTextFragment: false
107 }, opts);
108 return {
109 postcssPlugin: 'postcss-normalize-url',
110
111 OnceExit(css) {
112 css.walk(node => {
113 if (node.type === 'decl') {
114 return transformDecl(node, opts);
115 } else if (node.type === 'atrule' && node.name.toLowerCase() === 'namespace') {
116 return transformNamespace(node);
117 }
118 });
119 }
120
121 };
122}
123
124pluginCreator.postcss = true;
125var _default = pluginCreator;
126exports.default = _default;
127module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.