diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
| commit | c06f7ee0a40255214c477e13d9b956a7e07c2900 (patch) | |
| tree | f5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/postcss-discard-overridden | |
| parent | 3fd9400d4dccc25aa29b5702216732e0b7542073 (diff) | |
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/postcss-discard-overridden')
| -rw-r--r-- | node_modules/postcss-discard-overridden/LICENSE | 20 | ||||
| -rw-r--r-- | node_modules/postcss-discard-overridden/README.md | 158 | ||||
| -rw-r--r-- | node_modules/postcss-discard-overridden/package.json | 35 | ||||
| -rw-r--r-- | node_modules/postcss-discard-overridden/src/index.js | 94 |
4 files changed, 307 insertions, 0 deletions
diff --git a/node_modules/postcss-discard-overridden/LICENSE b/node_modules/postcss-discard-overridden/LICENSE new file mode 100644 index 00000000..f901ded7 --- /dev/null +++ b/node_modules/postcss-discard-overridden/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright 2016 Justineo <justice360@gmail.com> + +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-discard-overridden/README.md b/node_modules/postcss-discard-overridden/README.md new file mode 100644 index 00000000..ad69e50e --- /dev/null +++ b/node_modules/postcss-discard-overridden/README.md @@ -0,0 +1,158 @@ +# PostCSS Discard Overridden + +[PostCSS] plugin to discard overridden `@keyframes` or `@counter-style`. + +`@keyframes` or `@counter-style` will be overridden by those who share the same identifiers and appear later in stylesheets. So we can discard all of them except the last one. When defined inside a `@media` or `@supports` rule, `@keyframes` and `@counter-style` rules only override global rules in some of the client browsers so they need handled separately. This plugin has taken care of this and transforms the PostCss AST **safely**. + +[PostCSS]: https://github.com/postcss/postcss + +```css +@-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } +} +@keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } +} +@media (max-width: 500px) { + @-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + @keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + @-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } + } + @keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } + } + @supports (display: flex) { + @-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + @keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + } +} +@-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +``` + +```css +@media (max-width: 500px) { + @-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } + } + @keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 0.8; + } + } + @supports (display: flex) { + @-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + @keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } + } +} +@-webkit-keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +``` + +## 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). diff --git a/node_modules/postcss-discard-overridden/package.json b/node_modules/postcss-discard-overridden/package.json new file mode 100644 index 00000000..5a106d60 --- /dev/null +++ b/node_modules/postcss-discard-overridden/package.json @@ -0,0 +1,35 @@ +{ + "name": "postcss-discard-overridden", + "version": "6.0.0", + "description": "PostCSS plugin to discard overridden @keyframes or @counter-style.", + "main": "src/index.js", + "types": "types/index.d.ts", + "files": [ + "LICENSE", + "src" + ], + "keywords": [ + "postcss", + "css", + "postcss-plugin", + "at-rules", + "@keyframes", + "@counter-style" + ], + "author": "Justineo <justice360@gmail.com>", + "license": "MIT", + "repository": "cssnano/cssnano", + "bugs": { + "url": "https://github.com/cssnano/cssnano/issues" + }, + "homepage": "https://github.com/cssnano/cssnano", + "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-discard-overridden/src/index.js b/node_modules/postcss-discard-overridden/src/index.js new file mode 100644 index 00000000..97c8f62e --- /dev/null +++ b/node_modules/postcss-discard-overridden/src/index.js @@ -0,0 +1,94 @@ +'use strict'; +const OVERRIDABLE_RULES = new Set(['keyframes', 'counter-style']); +const SCOPE_RULES = new Set(['media', 'supports']); + +/** + * @param {string} prop + * @return {string} + */ +function vendorUnprefixed(prop) { + return prop.replace(/^-\w+-/, ''); +} + +/** + * @param {string} name + * @return {boolean} + */ +function isOverridable(name) { + return OVERRIDABLE_RULES.has(vendorUnprefixed(name.toLowerCase())); +} + +/** + * @param {string} name + * @return {boolean} + */ +function isScope(name) { + return SCOPE_RULES.has(vendorUnprefixed(name.toLowerCase())); +} + +/** + * @param {import('postcss').AtRule} node + * @return {string} + */ +function getScope(node) { + /** @type {import('postcss').Container<import('postcss').ChildNode> | import('postcss').Document | undefined} */ + let current = node.parent; + + const chain = [node.name.toLowerCase(), node.params]; + + while (current) { + if ( + current.type === 'atrule' && + isScope(/** @type import('postcss').AtRule */ (current).name) + ) { + chain.unshift( + /** @type import('postcss').AtRule */ (current).name + + ' ' + + /** @type import('postcss').AtRule */ (current).params + ); + } + current = current.parent; + } + + return chain.join('|'); +} + +/** + * @type {import('postcss').PluginCreator<void>} + * @return {import('postcss').Plugin} + */ +function pluginCreator() { + return { + postcssPlugin: 'postcss-discard-overridden', + prepare() { + const cache = new Map(); + /** @type {{node: import('postcss').AtRule, scope: string}[]} */ + const rules = []; + + return { + OnceExit(css) { + css.walkAtRules((node) => { + if (isOverridable(node.name)) { + const scope = getScope(node); + + cache.set(scope, node); + rules.push({ + node, + scope, + }); + } + }); + + rules.forEach((rule) => { + if (cache.get(rule.scope) !== rule.node) { + rule.node.remove(); + } + }); + }, + }; + }, + }; +} + +pluginCreator.postcss = true; +module.exports = pluginCreator; |
