diff --git a/plugins/css-blank-pseudo/.gitignore b/plugins/css-blank-pseudo/.gitignore
index 03fe35af5..7172b04f1 100644
--- a/plugins/css-blank-pseudo/.gitignore
+++ b/plugins/css-blank-pseudo/.gitignore
@@ -1,15 +1,6 @@
node_modules
-dist
package-lock.json
yarn.lock
-browser.js
-!src/browser.js
-browser-legacy.js
-*.log*
*.result.css
*.result.css.map
-!.editorconfig
-!.gitignore
-!.rollup.js
-!.tape.js
-!.travis.yml
+dist/*
diff --git a/plugins/css-blank-pseudo/.tape.mjs b/plugins/css-blank-pseudo/.tape.mjs
index 1c0aa6706..20a53c7d2 100644
--- a/plugins/css-blank-pseudo/.tape.mjs
+++ b/plugins/css-blank-pseudo/.tape.mjs
@@ -17,11 +17,35 @@ postcssTape(plugin)({
preserve: false
}
},
- 'generated-selector-cases': {
- message: 'correctly handles generated cases',
+ 'basic:wrong-replacewith': {
+ message: 'correctly warns when replace with is invalid',
warnings: 1,
+ options: {
+ replaceWith: '#css-blank'
+ }
+ },
+ 'examples/example': {
+ message: 'minimal example',
+ },
+ 'examples/example:preserve-false': {
+ message: 'minimal example',
options: {
preserve: false
}
},
+ 'examples/example:replacewith': {
+ message: 'minimal example',
+ options: {
+ replaceWith: '.css-blank'
+ }
+ },
+ 'browser': {
+ message: 'css for browser tests',
+ },
+ 'browser:replacewith': {
+ message: 'css for browser tests',
+ options: {
+ replaceWith: '.css-blank'
+ }
+ },
});
diff --git a/plugins/css-blank-pseudo/CHANGELOG.md b/plugins/css-blank-pseudo/CHANGELOG.md
index faab22d18..7701a1bfb 100644
--- a/plugins/css-blank-pseudo/CHANGELOG.md
+++ b/plugins/css-blank-pseudo/CHANGELOG.md
@@ -1,5 +1,28 @@
# Changes to CSS Blank Pseudo
+### Unreleased (major)
+
+- Updated: The polyfill now only attaches a single listener to the body so it's
+more efficient and also does less work at the MutationObserver handler.
+- Breaking: removed old CDN urls
+- Breaking: removed old CLI
+
+#### How to migrate:
+
+- If you use a CDN url, please update it.
+- Re-build your CSS with the new version of the library.
+
+```diff
+-
+-
++
+```
+
+```diff
+- cssBlankPseudo(document)
++ cssBlankPseudoInit()
+```
+
### 3.0.3 (February 5, 2022)
- Rebuild of browser polyfills
diff --git a/plugins/css-blank-pseudo/INSTALL.md b/plugins/css-blank-pseudo/INSTALL.md
index 79d87e3c5..1cc2e5d88 100644
--- a/plugins/css-blank-pseudo/INSTALL.md
+++ b/plugins/css-blank-pseudo/INSTALL.md
@@ -1,13 +1,13 @@
-# Installing CSS Blank Pseudo
+# Installing PostCSS Blank Pseudo
-[CSS Blank Pseudo] runs in all Node environments, with special instructions for:
+[PostCSS Blank Pseudo] runs in all Node environments, with special instructions for:
| [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
| --- | --- | --- | --- | --- | --- |
## Node
-Add [CSS Blank Pseudo] to your project:
+Add [PostCSS Blank Pseudo] to your project:
```bash
npm install postcss css-blank-pseudo --save-dev
@@ -32,7 +32,7 @@ Add [PostCSS CLI] to your project:
npm install postcss-cli css-blank-pseudo --save-dev
```
-Use [CSS Blank Pseudo] in your `postcss.config.js` configuration file:
+Use [PostCSS Blank Pseudo] in your `postcss.config.js` configuration file:
```js
const postcssBlankPseudo = require('css-blank-pseudo');
@@ -54,7 +54,7 @@ Add [PostCSS Loader] to your project:
npm install postcss-loader css-blank-pseudo --save-dev
```
-Use [CSS Blank Pseudo] in your Webpack configuration:
+Use [PostCSS Blank Pseudo] in your Webpack configuration:
```js
module.exports = {
@@ -98,7 +98,7 @@ Add [React App Rewired] and [React App Rewire PostCSS] to your project:
npm install react-app-rewired react-app-rewire-postcss css-blank-pseudo --save-dev
```
-Use [React App Rewire PostCSS] and [CSS Blank Pseudo] in your
+Use [React App Rewire PostCSS] and [PostCSS Blank Pseudo] in your
`config-overrides.js` file:
```js
@@ -120,7 +120,7 @@ Add [Gulp PostCSS] to your project:
npm install gulp-postcss css-blank-pseudo --save-dev
```
-Use [CSS Blank Pseudo] in your Gulpfile:
+Use [PostCSS Blank Pseudo] in your Gulpfile:
```js
const postcss = require('gulp-postcss');
@@ -145,7 +145,7 @@ Add [Grunt PostCSS] to your project:
npm install grunt-postcss css-blank-pseudo --save-dev
```
-Use [CSS Blank Pseudo] in your Gruntfile:
+Use [PostCSS Blank Pseudo] in your Gruntfile:
```js
const postcssBlankPseudo = require('css-blank-pseudo');
@@ -171,6 +171,6 @@ grunt.initConfig({
[PostCSS]: https://github.com/postcss/postcss
[PostCSS CLI]: https://github.com/postcss/postcss-cli
[PostCSS Loader]: https://github.com/postcss/postcss-loader
-[CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
+[PostCSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
[React App Rewired]: https://github.com/timarney/react-app-rewired
diff --git a/plugins/css-blank-pseudo/README-BROWSER.md b/plugins/css-blank-pseudo/README-BROWSER.md
deleted file mode 100644
index 5bec8b999..000000000
--- a/plugins/css-blank-pseudo/README-BROWSER.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# CSS Blank Pseudo for Browsers [][CSS Blank Pseudo]
-
-[![NPM Version][npm-img]][npm-url]
-[
][discord]
-
-[CSS Blank Pseudo] lets you style form elements when they are empty, following
-the [Selectors Level 4] specification.
-
-```css
-input {
- /* style an input */
-}
-
-input[blank] {
- /* style an input without a value */
-}
-```
-
-## Usage
-
-Add [CSS Blank Pseudo] to your build tool:
-
-```bash
-npm install css-blank-pseudo
-```
-
-Then include and initialize it on your document:
-
-```js
-const cssBlankPseudo = require('css-blank-pseudo/browser');
-
-cssBlankPseudo(document);
-```
-
-## Options
-
-[CSS Blank Pseudo] accepts a secondary paramater to configure the attribute or
-class name added to elements matching focused elements or containing focused
-elements.
-
-```js
-cssBlankPseudo(document, {
- attr: false,
- className: '.blank'
-});
-```
-
-Falsey values on either `attr` or `className` will disable setting the
-attribute or class name on elements matching `:blank`.
-
-[CSS Blank Pseudo] also accepts a secondary paramater to configure whether the
-polyfill is loaded regardless of support. If `force` is given a truthy value,
-then the polyfill will always execute.
-
-```js
-cssBlankPseudo(document, {
- force: true
-});
-```
-
-## Dependencies
-
-Web API's:
-
-- [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
-
-ECMA Script:
-
-- `Object.prototype.toString`
-- `Object.getOwnPropertyDescriptor`
-- `Object.defineProperty`
-- `Array.prototype.forEach`
-
-
-[discord]: https://discord.gg/bUadyRwkJS
-[npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
-[npm-url]: https://www.npmjs.com/package/css-blank-pseudo
-
-[CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
-[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
diff --git a/plugins/css-blank-pseudo/README-POSTCSS.md b/plugins/css-blank-pseudo/README-POSTCSS.md
deleted file mode 100644
index 18884b4eb..000000000
--- a/plugins/css-blank-pseudo/README-POSTCSS.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# CSS Blank Pseudo for PostCSS [
][CSS Blank Pseudo]
-
-[![NPM Version][npm-img]][npm-url]
-[
][discord]
-
-[CSS Blank Pseudo] lets you style form elements when they are empty, following
-the [Selectors Level 4] specification.
-
-```css
-input:blank {
- background-color: yellow;
-}
-
-/* becomes */
-
-.field[blank] label {
- background-color: yellow;
-}
-
-.field:blank label {
- background-color: yellow;
-}
-```
-
-[CSS Blank Pseudo] duplicates rules using the `:blank` pseudo-class with a
-`[blank]` attribute selector. This replacement selector can be changed
-using the `replaceWith` option. Also, the preservation of the original
-`:blank` rule can be disabled using the `preserve` option.
-
-## Usage
-
-Add [CSS Blank Pseudo] to your project:
-
-```bash
-npm install css-blank-pseudo --save-dev
-```
-
-Use [CSS Blank Pseudo] to process your CSS:
-
-```js
-const postcssBlankPseudo = require('css-blank-pseudo');
-
-postcssBlankPseudo.process(YOUR_CSS /*, processOptions, pluginOptions */);
-```
-
-Or use it as a [PostCSS] plugin:
-
-```js
-const postcss = require('postcss');
-const postcssBlankPseudo = require('css-blank-pseudo');
-
-postcss([
- postcssBlankPseudo(/* pluginOptions */)
-]).process(YOUR_CSS /*, processOptions */);
-```
-
-[CSS Blank Pseudo] 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
-
-### preserve
-
-The `preserve` option defines whether the original selector should remain. By
-default, the original selector is preserved.
-
-```js
-cssBlankPseudo({ preserve: false });
-```
-
-```css
-input:blank {
- background-color: yellow;
-}
-
-/* becomes */
-
-.field[blank] label {
- background-color: yellow;
-}
-```
-
-### replaceWith
-
-The `replaceWith` option defines the selector to replace `:blank`. By
-default, the replacement selector is `[blank]`.
-
-```js
-cssBlankPseudo({ replaceWith: '.blank' });
-```
-
-```css
-input:blank {
- background-color: yellow;
-}
-
-/* becomes */
-
-.field.blank label {
- background-color: yellow;
-}
-
-.field:blank label {
- background-color: yellow;
-}
-```
-
-[discord]: https://discord.gg/bUadyRwkJS
-[npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
-[npm-url]: https://www.npmjs.com/package/css-blank-pseudo
-
-[CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
-[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
diff --git a/plugins/css-blank-pseudo/README.md b/plugins/css-blank-pseudo/README.md
index b1cf7fd52..4179bd424 100644
--- a/plugins/css-blank-pseudo/README.md
+++ b/plugins/css-blank-pseudo/README.md
@@ -1,104 +1,163 @@
-# CSS Blank Pseudo [
][CSS Blank Pseudo]
+# PostCSS Blank Pseudo [
][postcss]
-[![NPM Version][npm-img]][npm-url]
-[
][discord]
+[
][npm-url] [
][css-url] [
][cli-url] [
][discord]
-[CSS Blank Pseudo] lets you style form elements when they are empty, following
+[PostCSS Blank Pseudo] lets you style form elements when they are empty, following
the [Selectors Level 4] specification.
-```css
-input {
- /* style an input */
+```pcss
+input:blank {
+ background-color: yellow;
}
+/* becomes */
+
+input[blank] {
+ background-color: yellow;
+}
input:blank {
- /* style an input without a value */
+ background-color: yellow;
}
```
## Usage
-From the command line, transform CSS files that use `:blank` selectors:
+Add [PostCSS Blank Pseudo] to your project:
```bash
-npx css-blank-pseudo SOURCE.css --output TRANSFORMED.css
+npm install postcss css-blank-pseudo --save-dev
```
-Next, use your transformed CSS with this script:
+Use it as a [PostCSS] plugin:
-```html
-
-
-
+```js
+const postcss = require('postcss');
+const postcssBlankPseudo = require('css-blank-pseudo');
+
+postcss([
+ postcssBlankPseudo(/* pluginOptions */)
+]).process(YOUR_CSS /*, processOptions */);
```
-⚠️ Please use a versioned url, like this : `https://unpkg.com/css-blank-pseudo@3.0.0/dist/browser-global.js`
-Without the version, you might unexpectedly get a new major version of the library with breaking changes.
+[PostCSS Blank Pseudo] 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) |
+| --- | --- | --- | --- | --- | --- |
-⚠️ If you were using an older version via a CDN, please update the entire url.
-The old URL will no longer work in a future release.
+## Options
-That’s it. The script works in most browsers.
+### preserve
-## How it works
+The `preserve` option determines whether the original notation
+is preserved. By default, it is preserved.
-The [PostCSS plugin](README-POSTCSS.md) clones rules containing `:blank`,
-replacing them with an alternative `[blank]` selector.
+```js
+postcssBlankPseudo({ preserve: false })
+```
-```css
+```pcss
input:blank {
- background-color: yellow;
+ background-color: yellow;
}
/* becomes */
input[blank] {
- background-color: yellow;
+ background-color: yellow;
}
+```
+
+### replaceWith
+
+The `replaceWith` option determines the selector to use when replacing
+the `:blank` pseudo. By default is `[blank]`
+```js
+postcssBlankPseudo({ replaceWith: '.css-blank' })
+```
+
+```pcss
input:blank {
- background-color: yellow;
+ background-color: yellow;
+}
+
+/* becomes */
+
+.foo {
+ color: blue;
+ color: red;
+}
+
+.baz {
+ color: green;
}
```
-Next, the [JavaScript library](README-BROWSER.md) adds a `blank` attribute to
-elements otherwise matching `:blank` natively.
+Note that changing this option implies that it needs to be passed to the
+browser polyfill as well.
+
+## Browser
+
+```js
+import cssBlankPseudoInit from 'css-blank-pseudo/browser';
+
+cssBlankPseudoInit();
+```
+
+or
```html
-
-
+
+
+
```
-## ⚠️ `:not(:blank)`
+[PostCSS Blank Pseudo] works in all major browsers, including Safari 6+ and
+Internet Explorer 9+ without any additional polyfills.
-with option : `preserve` `true`
+This plugin conditionally uses `MutationObserver` to ensure recently inserted
+inputs get correct styling upon insertion. If you intend to rely on that
+behaviour for browsers that do not support `MutationObserver`, you have two
+options:
-```css
-input:not(:blank) {
- background-color: yellow;
-}
+1. Polyfill `MutationObserver`. As long as it runs before `cssBlankPseudoInit`,
+the polyfill will work.
+2. If you don't want to polyfill `MutationObserver` you can also manually fire
+a `change` event upon insertion so they're automatically inspected by the
+polyfill.
-/* becomes */
+### Browser Usage
-input:not([blank]) {
- background-color: yellow;
-}
+#### force
-input:not(:blank) {
- background-color: yellow;
-}
+The `force` option determines whether the library runs even if the browser
+supports the selector or not. By default, it won't run if the browser does
+support the selector.
+
+```js
+cssBlankPseudoInit({ force: true });
```
-When you do not include the JS polyfill one will always match in browsers that support `:blank` natively.
-In browsers that do not support `:blank` natively the rule will be invalid.
+#### replaceWith
-_currently no browsers support `:blank`_
+Similar to the option for the PostCSS Plugin, `replaceWith` determines the
+attribute or class to apply to an element when it's considered to be `:blank`.
+
+```js
+cssBlankPseudoInit({ replaceWith: '.css-blank' });
+```
+This option should be used if it was changed at PostCSS configuration level.
+[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
+[css-url]: https://cssdb.org/#blank-pseudo-class
[discord]: https://discord.gg/bUadyRwkJS
-[npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
[npm-url]: https://www.npmjs.com/package/css-blank-pseudo
-[CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
-[PostCSS Preset Env]: https://preset-env.cssdb.org/
-[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
+[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
+[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
+[PostCSS]: https://github.com/postcss/postcss
+[PostCSS Loader]: https://github.com/postcss/postcss-loader
+[PostCSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
+[Selectors Level 4]: https://www.w3.org/TR/selectors-4/#blank
diff --git a/plugins/css-blank-pseudo/docs/README.md b/plugins/css-blank-pseudo/docs/README.md
new file mode 100644
index 000000000..fbd96f626
--- /dev/null
+++ b/plugins/css-blank-pseudo/docs/README.md
@@ -0,0 +1,127 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+