![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/vreg/node_modules/postcss-url/src/lib/ |
'use strict'; /** * Optimize encoding SVG files (IE9+, Android 3+) * @see https://codepen.io/tigt/post/optimizing-svgs-in-data-uris * * @param {String} svgContent * @returns {String} */ const optimizedSvgEncode = (svgContent) => { const result = encodeURIComponent(svgContent) .replace(/%3D/g, '=') .replace(/%3A/g, ':') .replace(/%2F/g, '/') .replace(/%22/g, "'") .replace(/%2C/g, ',') .replace(/%3B/g, ';'); // Lowercase the hex-escapes for better gzipping return result.replace(/(%[0-9A-Z]{2})/g, (matched, AZ) => { return AZ.toLowerCase(); }); }; /** * Encoding file contents to string * * @param {PostcssUrl~File} file * @param {String} [encodeType=base64|encodeURI|encodeURIComponent] * @param {Boolean} [shouldOptimizeURIEncode] * @returns {string} */ module.exports = (file, encodeType, shouldOptimizeSvgEncode) => { const dataMime = `data:${file.mimeType}`; if (encodeType === 'base64') { return `${dataMime};base64,${file.contents.toString('base64')}`; } const encodeFunc = encodeType === 'encodeURI' ? encodeURI : encodeURIComponent; const content = file.contents.toString('utf8') // removing new lines .replace(/\n+/g, ''); let encodedStr = (shouldOptimizeSvgEncode && encodeType === 'encodeURIComponent') ? optimizedSvgEncode(content) : encodeFunc(content); encodedStr = encodedStr .replace(/%20/g, ' ') .replace(/#/g, '%23'); return `${dataMime},${encodedStr}`; };