This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
# Changes to PostCSS Browser Comments
### 4.0.0 (April 28, 2021)
- Updated: PostCSS 8 compatibility (major)
### 3.0.0 (May 24, 2019)
- Updated: Node 8+ compatibility (major)
### 2.0.0 (September 6, 2018)
- Update to PostCSS 7.0.2 (major)
- Update to browserslist 4.1.1 (major)
### 1.0.0 (June 15, 2018)
- Initial version

View File

@@ -0,0 +1,108 @@
# CC0 1.0 Universal
## Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator and
subsequent owner(s) (each and all, an “owner”) of an original work of
authorship and/or a database (each, a “Work”).
Certain owners wish to permanently relinquish those rights to a Work for the
purpose of contributing to a commons of creative, cultural and scientific works
(“Commons”) that the public can reliably and without fear of later claims of
infringement build upon, modify, incorporate in other works, reuse and
redistribute as freely as possible in any form whatsoever and for any purposes,
including without limitation commercial purposes. These owners may contribute
to the Commons to promote the ideal of a free culture and the further
production of creative, cultural and scientific works, or to gain reputation or
greater distribution for their Work in part through the use and efforts of
others.
For these and/or other purposes and motivations, and without any expectation of
additional consideration or compensation, the person associating CC0 with a
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
publicly distribute the Work under its terms, with knowledge of his or her
Copyright and Related Rights in the Work and the meaning and intended legal
effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights (“Copyright and
Related Rights”). Copyright and Related Rights include, but are not limited
to, the following:
1. the right to reproduce, adapt, distribute, perform, display, communicate,
and translate a Work;
2. moral rights retained by the original author(s) and/or performer(s);
3. publicity and privacy rights pertaining to a persons image or likeness
depicted in a Work;
4. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(i), below;
5. rights protecting the extraction, dissemination, use and reuse of data in
a Work;
6. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation thereof,
including any amended or successor version of such directive); and
7. other similar, equivalent or corresponding rights throughout the world
based on applicable law or treaty, and any national implementations
thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of,
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
unconditionally waives, abandons, and surrenders all of Affirmers Copyright
and Related Rights and associated claims and causes of action, whether now
known or unknown (including existing as well as future claims and causes of
action), in the Work (i) in all territories worldwide, (ii) for the maximum
duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number of
copies, and (iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the “Waiver”). Affirmer
makes the Waiver for the benefit of each member of the public at large and
to the detriment of Affirmers heirs and successors, fully intending that
such Waiver shall not be subject to revocation, rescission, cancellation,
termination, or any other legal or equitable action to disrupt the quiet
enjoyment of the Work by the public as contemplated by Affirmers express
Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be
judged legally invalid or ineffective under applicable law, then the Waiver
shall be preserved to the maximum extent permitted taking into account
Affirmers express Statement of Purpose. In addition, to the extent the
Waiver is so judged Affirmer hereby grants to each affected person a
royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmers Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number of
copies, and (iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the “License”). The License
shall be deemed effective as of the date CC0 was applied by Affirmer to the
Work. Should any part of the License for any reason be judged legally
invalid or ineffective under applicable law, such partial invalidity or
ineffectiveness shall not invalidate the remainder of the License, and in
such case Affirmer hereby affirms that he or she will not (i) exercise any
of his or her remaining Copyright and Related Rights in the Work or (ii)
assert any associated claims and causes of action with respect to the Work,
in either case contrary to Affirmers express Statement of Purpose.
4. Limitations and Disclaimers.
1. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
2. Affirmer offers the Work as-is and makes no representations or warranties
of any kind concerning the Work, express, implied, statutory or
otherwise, including without limitation warranties of title,
merchantability, fitness for a particular purpose, non infringement, or
the absence of latent or other defects, accuracy, or the present or
absence of errors, whether or not discoverable, all to the greatest
extent permissible under applicable law.
3. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any persons Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the Work.
4. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to this
CC0 or use of the Work.
For more information, please see
http://creativecommons.org/publicdomain/zero/1.0/.

View File

@@ -0,0 +1,114 @@
# PostCSS Browser Comments [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Support Chat][git-img]][git-url]
[PostCSS Browser Comments] lets you keep only the CSS you need based on
comments and your [browserslist].
```css
/**
* Prevent adjustments of font size after orientation changes in IE and iOS.
*/
html {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
```
The comment and rule above would be removed with the following browserslist:
```yml
last 2 chrome versions
```
The rule below would be more carefully altered:
```css
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/* with a `last 2 firefox versions` browserslist becomes */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
}
```
---
[PostCSS Browser Comments] can remove rules based upon the comment above them,
or it can remove declarations using numbered comments that reference the rule
above them. In the later case, when all of the numbered comments are removed,
then the entire rule and comment are also removed.
## Usage
Add [PostCSS Browser Comments] to your project:
```bash
npm install postcss postcss-browser-comments --save-dev
```
Use [PostCSS Browser Comments] to process your CSS:
```js
const postcssBrowserComments = require('postcss-browser-comments');
postcssBrowserComments.process(YOUR_CSS /*, processOptions, pluginOptions */);
```
Or use it as a [PostCSS] plugin:
```js
const postcss = require('postcss');
const postcssBrowserComments = require('postcss-browser-comments');
postcss([
postcssBrowserComments(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```
[PostCSS Browser Comments] runs in all Node environments, with special instructions for:
| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
| --- | --- | --- | --- | --- | --- |
## Options
### browsers
The `browsers` option overrides of the projects browserslist.
```js
postcssBrowserComments({
browsers: 'last 2 versions'
});
```
[cli-img]: https://img.shields.io/travis/csstools/postcss-browser-comments/main.svg
[cli-url]: https://travis-ci.org/csstools/postcss-browser-comments
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[git-url]: https://gitter.im/postcss/postcss
[npm-img]: https://img.shields.io/npm/v/postcss-browser-comments.svg
[npm-url]: https://www.npmjs.com/package/postcss-browser-comments
[browserslist]: https://github.com/browserslist/browserslist
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Browser Comments]: https://github.com/csstools/postcss-browser-comments

View File

@@ -0,0 +1,90 @@
var browserslist = require('browserslist');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var browserslist__default = /*#__PURE__*/_interopDefaultLegacy(browserslist);
const plugin = opts => {
return {
postcssPlugin: 'postcss-browser-comments',
Once(root) {
// client browserslist
const clientBrowserList = browserslist__default['default'](Object(opts).browsers || null, {
path: root.source && root.source.input && root.source.input.file
}); // root children references
const references = root.nodes.slice(0); // for each child node of the root children references
for (const node of references) {
// if the node is a comment browser comment node
if (isBrowserCommentNode(node)) {
// rule following the browser comment
const rule = node.next(); // browser data
const browserdata = getBrowserData(node.text);
if (browserdata.isNumbered) {
rule.nodes.filter(isBrowserReferenceCommentNode).map(comment => {
const browserdataIndex = parseFloat(comment.text) - 1;
const browserslistPart = browserdata.browserslist[browserdataIndex]; // whether to remove the rule if the comment browserslist does not match the client browserslist
const removeRule = !clientBrowserList.some(clientBrowser => browserslist__default['default'](browserslistPart).some(commentBrowser => commentBrowser === clientBrowser)); // conditionally remove the declaration and reference comment
if (removeRule) {
comment.prev().remove();
comment.remove();
}
}); // conditionally remove the empty rule and comment
if (!rule.nodes.length) {
rule.remove();
node.remove();
}
} else {
// whether to remove the rule if the comment browserslist does not match the client browserslist
const removeRule = !clientBrowserList.some(clientBrowser => browserslist__default['default'](browserdata.browserslist).some(commentBrowser => commentBrowser === clientBrowser)); // conditionally remove the rule and comment
if (removeRule) {
rule.remove();
node.remove();
}
}
}
}
}
};
};
plugin.postcss = true;
const isBrowserCommentNode = node => node.type === 'comment' && isBrowserCommentNodeRegExp.test(node.text) && node.next().type === 'rule';
const isBrowserCommentNodeRegExp = /^\*\n * /; // returns whether a node is a browser reference comment
const isBrowserReferenceCommentNode = node => node.type === 'comment' && isBrowserReferenceCommentNodeRegExp.test(node.text);
const isBrowserReferenceCommentNodeRegExp = /^\d+$/; // returns browser data from comment text
const getBrowserData = text => {
const browserDataNumbered = text.match(browserDataMutliRegExp);
const isNumbered = Boolean(browserDataNumbered);
return {
browserslist: isNumbered ? browserDataNumbered.map(browserslistPart => getBrowsersList(browserslistPart.replace(browserDataNumberedNewlineRegExp, '$1'))) : getBrowsersList(text.replace(browserDataNewlineRegExp, '')),
isNumbered
};
};
const browserDataMutliRegExp = /(\n \* \d+\. (?:[^\n]+|\n \* {4,})+)/g;
const browserDataNewlineRegExp = /^\*\n \* ?|\n \*/g;
const browserDataNumberedNewlineRegExp = /\n \* (?:( )\s*)?/g; // returns a browserlist from comment text
const getBrowsersList = text => text.split(getBrowsersListInSplitRegExp).slice(1).map(part => part.split(getBrowsersListAndSplitRegExp).filter(part2 => part2)).reduce((acc, val) => acc.concat(val), []).map(part => part.replace(getBrowsersListQueryRegExp, ($0, browser, query) => browser === 'all' ? '> 0%' : `${browser}${query ? /^((?:\d*\.)?\d+)-$/.test(query) ? ` <= ${query.slice(0, -1)}` : ` ${query}` : ' > 0'}`).toLowerCase());
const getBrowsersListInSplitRegExp = /\s+in\s+/;
const getBrowsersListAndSplitRegExp = /(?: and|, and|,)/;
const getBrowsersListQueryRegExp = /^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;
module.exports = plugin;
//# sourceMappingURL=index.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,86 @@
import browserslist from 'browserslist';
const plugin = opts => {
return {
postcssPlugin: 'postcss-browser-comments',
Once(root) {
// client browserslist
const clientBrowserList = browserslist(Object(opts).browsers || null, {
path: root.source && root.source.input && root.source.input.file
}); // root children references
const references = root.nodes.slice(0); // for each child node of the root children references
for (const node of references) {
// if the node is a comment browser comment node
if (isBrowserCommentNode(node)) {
// rule following the browser comment
const rule = node.next(); // browser data
const browserdata = getBrowserData(node.text);
if (browserdata.isNumbered) {
rule.nodes.filter(isBrowserReferenceCommentNode).map(comment => {
const browserdataIndex = parseFloat(comment.text) - 1;
const browserslistPart = browserdata.browserslist[browserdataIndex]; // whether to remove the rule if the comment browserslist does not match the client browserslist
const removeRule = !clientBrowserList.some(clientBrowser => browserslist(browserslistPart).some(commentBrowser => commentBrowser === clientBrowser)); // conditionally remove the declaration and reference comment
if (removeRule) {
comment.prev().remove();
comment.remove();
}
}); // conditionally remove the empty rule and comment
if (!rule.nodes.length) {
rule.remove();
node.remove();
}
} else {
// whether to remove the rule if the comment browserslist does not match the client browserslist
const removeRule = !clientBrowserList.some(clientBrowser => browserslist(browserdata.browserslist).some(commentBrowser => commentBrowser === clientBrowser)); // conditionally remove the rule and comment
if (removeRule) {
rule.remove();
node.remove();
}
}
}
}
}
};
};
plugin.postcss = true;
const isBrowserCommentNode = node => node.type === 'comment' && isBrowserCommentNodeRegExp.test(node.text) && node.next().type === 'rule';
const isBrowserCommentNodeRegExp = /^\*\n * /; // returns whether a node is a browser reference comment
const isBrowserReferenceCommentNode = node => node.type === 'comment' && isBrowserReferenceCommentNodeRegExp.test(node.text);
const isBrowserReferenceCommentNodeRegExp = /^\d+$/; // returns browser data from comment text
const getBrowserData = text => {
const browserDataNumbered = text.match(browserDataMutliRegExp);
const isNumbered = Boolean(browserDataNumbered);
return {
browserslist: isNumbered ? browserDataNumbered.map(browserslistPart => getBrowsersList(browserslistPart.replace(browserDataNumberedNewlineRegExp, '$1'))) : getBrowsersList(text.replace(browserDataNewlineRegExp, '')),
isNumbered
};
};
const browserDataMutliRegExp = /(\n \* \d+\. (?:[^\n]+|\n \* {4,})+)/g;
const browserDataNewlineRegExp = /^\*\n \* ?|\n \*/g;
const browserDataNumberedNewlineRegExp = /\n \* (?:( )\s*)?/g; // returns a browserlist from comment text
const getBrowsersList = text => text.split(getBrowsersListInSplitRegExp).slice(1).map(part => part.split(getBrowsersListAndSplitRegExp).filter(part2 => part2)).reduce((acc, val) => acc.concat(val), []).map(part => part.replace(getBrowsersListQueryRegExp, ($0, browser, query) => browser === 'all' ? '> 0%' : `${browser}${query ? /^((?:\d*\.)?\d+)-$/.test(query) ? ` <= ${query.slice(0, -1)}` : ` ${query}` : ' > 0'}`).toLowerCase());
const getBrowsersListInSplitRegExp = /\s+in\s+/;
const getBrowsersListAndSplitRegExp = /(?: and|, and|,)/;
const getBrowsersListQueryRegExp = /^\s*(\w+)(?: ((?:(?:\d*\.)?\d+-)?(?:\d*\.)?\d+[+-]?))?.*$/;
export default plugin;
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,71 @@
{
"name": "postcss-browser-comments",
"version": "4.0.0",
"description": "Keep only the CSS you need based on comments and your browserslist",
"author": "Jonathan Neal <csstools@hotmail.com>",
"license": "CC0-1.0",
"repository": "csstools/postcss-browser-comments",
"homepage": "https://github.com/csstools/postcss-browser-comments#readme",
"bugs": "https://github.com/csstools/postcss-browser-comments/issues",
"main": "index.cjs",
"module": "index.mjs",
"files": [
"index.cjs",
"index.cjs.map",
"index.mjs",
"index.mjs.map"
],
"scripts": {
"prepublishOnly": "npm test",
"build": "rollup --config .rollup.js --silent",
"lint": "eslint *.js --cache --ignore-path .gitignore --quiet",
"test": "npm run lint && npm run build && npm run tape",
"tape": "postcss-tape"
},
"engines": {
"node": ">=8"
},
"peerDependencies": {
"browserslist": ">=4",
"postcss": ">=8"
},
"devDependencies": {
"@babel/core": "7.13.16",
"@babel/preset-env": "7.13.15",
"browserslist": "4.1.1",
"eslint": "7.25.0",
"postcss": "8.2.13",
"postcss-tape": "6.0.1",
"pre-commit": "1.2.2",
"rollup": "2.46.0",
"rollup-plugin-babel": "4.3.2"
},
"eslintConfig": {
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
},
"rules": {
"semi": [
"error",
"never"
]
}
},
"keywords": [
"postcss",
"css",
"postcss-plugin",
"browserslists",
"browserlists",
"browsers",
"lists",
"support",
"caniuse",
"target"
]
}