summaryrefslogtreecommitdiff
path: root/node_modules/postcss-normalize-url
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:05:55 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:05:55 +0800
commitc06f7ee0a40255214c477e13d9b956a7e07c2900 (patch)
treef5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/postcss-normalize-url
parent3fd9400d4dccc25aa29b5702216732e0b7542073 (diff)
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/postcss-normalize-url')
-rw-r--r--node_modules/postcss-normalize-url/LICENSE-MIT22
-rw-r--r--node_modules/postcss-normalize-url/README.md48
-rw-r--r--node_modules/postcss-normalize-url/package.json44
-rw-r--r--node_modules/postcss-normalize-url/src/index.js151
-rw-r--r--node_modules/postcss-normalize-url/src/normalize.js153
-rw-r--r--node_modules/postcss-normalize-url/types/index.d.ts9
-rw-r--r--node_modules/postcss-normalize-url/types/normalize.d.ts6
7 files changed, 433 insertions, 0 deletions
diff --git a/node_modules/postcss-normalize-url/LICENSE-MIT b/node_modules/postcss-normalize-url/LICENSE-MIT
new file mode 100644
index 00000000..fd0e863a
--- /dev/null
+++ b/node_modules/postcss-normalize-url/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/postcss-normalize-url/README.md b/node_modules/postcss-normalize-url/README.md
new file mode 100644
index 00000000..23c9d05a
--- /dev/null
+++ b/node_modules/postcss-normalize-url/README.md
@@ -0,0 +1,48 @@
+# [postcss][postcss]-normalize-url
+
+> [Normalize URLs](https://github.com/sindresorhus/normalize-url) with PostCSS.
+
+## Install
+
+With [npm](https://npmjs.org/package/postcss-normalize-url) do:
+
+```
+npm install postcss-normalize-url --save
+```
+
+## Example
+
+### Input
+
+```css
+h1 {
+ background: url("http://site.com:80/image.jpg")
+}
+```
+
+### Output
+
+```css
+h1 {
+ background: url(http://site.com/image.jpg)
+}
+```
+
+Note that this module will also try to normalize relative URLs, and is capable
+of stripping unnecessary quotes. For more examples, see the [tests](test.js).
+
+## Usage
+
+See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
+examples for your environment.
+
+## Contributors
+
+See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
+
+## License
+
+MIT © [Ben Briggs](http://beneb.info)
+
+[docs]: https://github.com/sindresorhus/normalize-url#options
+[postcss]: https://github.com/postcss/postcss
diff --git a/node_modules/postcss-normalize-url/package.json b/node_modules/postcss-normalize-url/package.json
new file mode 100644
index 00000000..256d45f2
--- /dev/null
+++ b/node_modules/postcss-normalize-url/package.json
@@ -0,0 +1,44 @@
+{
+ "name": "postcss-normalize-url",
+ "version": "6.0.0",
+ "description": "Normalize URLs with PostCSS",
+ "main": "src/index.js",
+ "types": "types/index.d.ts",
+ "files": [
+ "src",
+ "LICENSE-MIT",
+ "types"
+ ],
+ "keywords": [
+ "css",
+ "normalize",
+ "optimise",
+ "optimisation",
+ "postcss",
+ "postcss-plugin",
+ "url"
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "postcss-value-parser": "^4.2.0"
+ },
+ "homepage": "https://github.com/cssnano/cssnano",
+ "author": {
+ "name": "Ben Briggs",
+ "email": "beneb.info@gmail.com",
+ "url": "http://beneb.info"
+ },
+ "repository": "cssnano/cssnano",
+ "bugs": {
+ "url": "https://github.com/cssnano/cssnano/issues"
+ },
+ "engines": {
+ "node": "^14 || ^16 || >=18.0"
+ },
+ "devDependencies": {
+ "postcss": "^8.2.15"
+ },
+ "peerDependencies": {
+ "postcss": "^8.2.15"
+ }
+} \ No newline at end of file
diff --git a/node_modules/postcss-normalize-url/src/index.js b/node_modules/postcss-normalize-url/src/index.js
new file mode 100644
index 00000000..3542dcf8
--- /dev/null
+++ b/node_modules/postcss-normalize-url/src/index.js
@@ -0,0 +1,151 @@
+'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 (e) {
+ 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;
diff --git a/node_modules/postcss-normalize-url/src/normalize.js b/node_modules/postcss-normalize-url/src/normalize.js
new file mode 100644
index 00000000..e6597e0d
--- /dev/null
+++ b/node_modules/postcss-normalize-url/src/normalize.js
@@ -0,0 +1,153 @@
+'use strict';
+/* Derived from normalize-url https://github.com/sindresorhus/normalize-url/main/index.js by Sindre Sorhus */
+
+// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
+const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
+const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
+
+const supportedProtocols = new Set(['https:', 'http:', 'file:']);
+
+/**
+ * @param {string} urlString
+ * @return {boolean} */
+function hasCustomProtocol(urlString) {
+ try {
+ const { protocol } = new URL(urlString);
+ return protocol.endsWith(':') && !supportedProtocols.has(protocol);
+ } catch {
+ return false;
+ }
+}
+
+/**
+ * @param {string} urlString
+ * @return {string} */
+function normalizeDataURL(urlString) {
+ const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(
+ urlString
+ );
+
+ if (!match) {
+ throw new Error(`Invalid URL: ${urlString}`);
+ }
+
+ let { type, data, hash } =
+ /** @type {{type: string, data: string, hash: string}} */ (match.groups);
+ const mediaType = type.split(';');
+
+ let isBase64 = false;
+ if (mediaType[mediaType.length - 1] === 'base64') {
+ mediaType.pop();
+ isBase64 = true;
+ }
+
+ // Lowercase MIME type
+ const mimeType = mediaType.shift()?.toLowerCase() ?? '';
+ const attributes = mediaType
+ .map(
+ /** @type {(string: string) => string} */ (attribute) => {
+ let [key, value = ''] = attribute
+ .split('=')
+ .map(
+ /** @type {(string: string) => string} */ (string) => string.trim()
+ );
+
+ // Lowercase `charset`
+ if (key === 'charset') {
+ value = value.toLowerCase();
+
+ if (value === DATA_URL_DEFAULT_CHARSET) {
+ return '';
+ }
+ }
+
+ return `${key}${value ? `=${value}` : ''}`;
+ }
+ )
+ .filter(Boolean);
+
+ const normalizedMediaType = [...attributes];
+
+ if (isBase64) {
+ normalizedMediaType.push('base64');
+ }
+
+ if (
+ normalizedMediaType.length > 0 ||
+ (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)
+ ) {
+ normalizedMediaType.unshift(mimeType);
+ }
+
+ return `data:${normalizedMediaType.join(';')},${
+ isBase64 ? data.trim() : data
+ }${hash ? `#${hash}` : ''}`;
+}
+
+/**
+ * @param {string} urlString
+ * @return {string}
+ */
+function normalizeUrl(urlString) {
+ urlString = urlString.trim();
+
+ // Data URL
+ if (/^data:/i.test(urlString)) {
+ return normalizeDataURL(urlString);
+ }
+
+ if (hasCustomProtocol(urlString)) {
+ return urlString;
+ }
+
+ const hasRelativeProtocol = urlString.startsWith('//');
+ const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
+
+ // Prepend protocol
+ if (!isRelativeUrl) {
+ urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, 'http:');
+ }
+
+ const urlObject = new URL(urlString);
+
+ // Remove duplicate slashes if not preceded by a protocol
+ if (urlObject.pathname) {
+ urlObject.pathname = urlObject.pathname.replace(
+ /(?<!\b[a-z][a-z\d+\-.]{1,50}:)\/{2,}/g,
+ '/'
+ );
+ }
+
+ // Decode URI octets
+ if (urlObject.pathname) {
+ try {
+ urlObject.pathname = decodeURI(urlObject.pathname);
+ } catch {
+ /* Do nothing */
+ }
+ }
+
+ if (urlObject.hostname) {
+ // Remove trailing dot
+ urlObject.hostname = urlObject.hostname.replace(/\.$/, '');
+ }
+
+ urlObject.pathname = urlObject.pathname.replace(/\/$/, '');
+
+ // Take advantage of many of the Node `url` normalizations
+ urlString = urlObject.toString();
+
+ // Remove ending `/`
+ if (urlObject.pathname === '/' && urlObject.hash === '') {
+ urlString = urlString.replace(/\/$/, '');
+ }
+
+ // Restore relative protocol
+ if (hasRelativeProtocol) {
+ urlString = urlString.replace(/^http:\/\//, '//');
+ }
+
+ return urlString;
+}
+
+module.exports = normalizeUrl;
diff --git a/node_modules/postcss-normalize-url/types/index.d.ts b/node_modules/postcss-normalize-url/types/index.d.ts
new file mode 100644
index 00000000..d2beadb6
--- /dev/null
+++ b/node_modules/postcss-normalize-url/types/index.d.ts
@@ -0,0 +1,9 @@
+export = pluginCreator;
+/**
+ * @type {import('postcss').PluginCreator<void>}
+ * @return {import('postcss').Plugin}
+ */
+declare function pluginCreator(): import('postcss').Plugin;
+declare namespace pluginCreator {
+ const postcss: true;
+}
diff --git a/node_modules/postcss-normalize-url/types/normalize.d.ts b/node_modules/postcss-normalize-url/types/normalize.d.ts
new file mode 100644
index 00000000..e8aae04e
--- /dev/null
+++ b/node_modules/postcss-normalize-url/types/normalize.d.ts
@@ -0,0 +1,6 @@
+export = normalizeUrl;
+/**
+ * @param {string} urlString
+ * @return {string}
+ */
+declare function normalizeUrl(urlString: string): string;