| Server IP : 82.148.16.210 / Your IP : 216.73.216.244 Web Server : nginx/1.29.5 System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/projects/env4/src/dev/frontend5/node_modules/postcss-normalize-url/src/ |
Upload File : |
'use strict';
const path = require('path');
const valueParser = require('postcss-value-parser');
const normalize = require('./normalize.js');
const multiline = /\\[\r\n]/;
// eslint-disable-next-line no-useless-escape
const escapeChars = /([\s\(\)"'])/g;
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
// Windows paths like `c:\`
const WINDOWS_PATH_REGEX = /^[a-zA-Z]:\\/;
/**
* Originally in sindresorhus/is-absolute-url
*
* @param {string} url
*/
function isAbsolute(url) {
if (WINDOWS_PATH_REGEX.test(url)) {
return false;
}
return ABSOLUTE_URL_REGEX.test(url);
}
/**
* @param {string} url
* @return {string}
*/
function convert(url) {
if (isAbsolute(url) || url.startsWith('//')) {
let normalizedURL;
try {
normalizedURL = normalize(url);
} catch {
normalizedURL = url;
}
return normalizedURL;
}
// `path.normalize` always returns backslashes on Windows, need replace in `/`
return path.normalize(url).replace(new RegExp('\\' + path.sep, 'g'), '/');
}
/**
* @param {import('postcss').AtRule} rule
* @return {void}
*/
function transformNamespace(rule) {
rule.params = valueParser(rule.params)
.walk((node) => {
if (
node.type === 'function' &&
node.value.toLowerCase() === 'url' &&
node.nodes.length
) {
/** @type {valueParser.Node} */ (node).type = 'string';
/** @type {any} */ (node).quote =
node.nodes[0].type === 'string' ? node.nodes[0].quote : '"';
node.value = node.nodes[0].value;
}
if (node.type === 'string') {
node.value = node.value.trim();
}
return false;
})
.toString();
}
/**
* @param {import('postcss').Declaration} decl
* @return {void}
*/
function transformDecl(decl) {
decl.value = valueParser(decl.value)
.walk((node) => {
if (node.type !== 'function' || node.value.toLowerCase() !== 'url') {
return false;
}
node.before = node.after = '';
if (!node.nodes.length) {
return false;
}
let url = node.nodes[0];
let escaped;
url.value = url.value.trim().replace(multiline, '');
// Skip empty URLs
// Empty URL function equals request to current stylesheet where it is declared
if (url.value.length === 0) {
/** @type {any} */ (url).quote = '';
return false;
}
if (/^data:(.*)?,/i.test(url.value)) {
return false;
}
if (!/^.+-extension:\//i.test(url.value)) {
url.value = convert(url.value);
}
if (escapeChars.test(url.value) && url.type === 'string') {
escaped = url.value.replace(escapeChars, '\\$1');
if (escaped.length < url.value.length + 2) {
url.value = escaped;
/** @type {valueParser.Node} */ (url).type = 'word';
}
} else {
url.type = 'word';
}
return false;
})
.toString();
}
/**
* @type {import('postcss').PluginCreator<void>}
* @return {import('postcss').Plugin}
*/
function pluginCreator() {
return {
postcssPlugin: 'postcss-normalize-url',
OnceExit(css) {
css.walk((node) => {
if (node.type === 'decl') {
return transformDecl(node);
} else if (
node.type === 'atrule' &&
node.name.toLowerCase() === 'namespace'
) {
return transformNamespace(node);
}
});
},
};
}
pluginCreator.postcss = true;
module.exports = pluginCreator;