css-blank-pseudo 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Changes to CSS Blank Pseudo
2
2
 
3
+ ### 4.0.0 (July 8, 2022)
4
+
5
+ - Updated: The polyfill now only attaches a single listener to the body so it's
6
+ more efficient and also does less work at the MutationObserver handler.
7
+ - Breaking: removed old CDN urls
8
+ - Breaking: removed old CLI
9
+ - Fix case insensitive matching.
10
+
11
+ #### How to migrate:
12
+
13
+ - If you use a CDN url, please update it.
14
+ - Re-build your CSS with the new version of the library.
15
+
16
+ ```diff
17
+ - <script src="https://unpkg.com/css-blank-pseudo/browser"></script>
18
+ - <script src="https://unpkg.com/css-blank-pseudo/browser.min"></script>
19
+ + <script src="https://unpkg.com/css-blank-pseudo/dist/browser-global.js"></script>
20
+ ```
21
+
22
+ ```diff
23
+ - cssBlankPseudo(document)
24
+ + cssBlankPseudoInit()
25
+ ```
26
+
27
+ ```diff
28
+ - cssBlankPseudo({
29
+ - attr: false,
30
+ - className: 'blank'
31
+ - })
32
+ + cssBlankPseudoInit({
33
+ + replaceWith: '.blank'
34
+ + })
35
+ ```
36
+
37
+ ### 3.0.3 (February 5, 2022)
38
+
39
+ - Rebuild of browser polyfills
40
+
41
+ ### 3.0.2 (January 2, 2022)
42
+
43
+ - Removed Sourcemaps from package tarball.
44
+ - Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
45
+
3
46
  ### 3.0.1 (December 27, 2021)
4
47
 
5
48
  - Fixed: require/import paths for browser script
package/README.md CHANGED
@@ -1,105 +1,166 @@
1
- # CSS Blank Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Blank Pseudo]
1
+ # PostCSS Blank Pseudo [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
2
2
 
3
- [![NPM Version][npm-img]][npm-url]
4
- [![Support Chat][git-img]][git-url]
3
+ [<img alt="npm version" src="https://img.shields.io/npm/v/css-blank-pseudo.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/blank-pseudo-class.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
5
4
 
6
- [CSS Blank Pseudo] lets you style form elements when they are empty, following
5
+ [PostCSS Blank Pseudo] lets you style form elements when they are empty, following
7
6
  the [Selectors Level 4] specification.
8
7
 
9
- ```css
10
- input {
11
- /* style an input */
8
+ ```pcss
9
+ input:blank {
10
+ background-color: yellow;
12
11
  }
13
12
 
13
+ /* becomes */
14
+
15
+ input[blank].js-blank-pseudo, .js-blank-pseudo input[blank] {
16
+ background-color: yellow;
17
+ }
14
18
  input:blank {
15
- /* style an input without a value */
19
+ background-color: yellow;
16
20
  }
17
21
  ```
18
22
 
19
23
  ## Usage
20
24
 
21
- From the command line, transform CSS files that use `:blank` selectors:
25
+ Add [PostCSS Blank Pseudo] to your project:
22
26
 
23
27
  ```bash
24
- npx css-blank-pseudo SOURCE.css --output TRANSFORMED.css
28
+ npm install postcss css-blank-pseudo --save-dev
25
29
  ```
26
30
 
27
- Next, use your transformed CSS with this script:
31
+ Use it as a [PostCSS] plugin:
28
32
 
29
- ```html
30
- <link rel="stylesheet" href="TRANSFORMED.css">
31
- <script src="https://unpkg.com/css-blank-pseudo/dist/browser-global.js"></script>
32
- <script>cssBlankPseudo(document)</script>
33
+ ```js
34
+ const postcss = require('postcss');
35
+ const postcssBlankPseudo = require('css-blank-pseudo');
36
+
37
+ postcss([
38
+ postcssBlankPseudo(/* pluginOptions */)
39
+ ]).process(YOUR_CSS /*, processOptions */);
33
40
  ```
34
41
 
35
- ⚠️ Please use a versioned url, like this : `https://unpkg.com/css-blank-pseudo@3.0.0/dist/browser-global.js`
36
- Without the version, you might unexpectedly get a new major version of the library with breaking changes.
42
+ [PostCSS Blank Pseudo] runs in all Node environments, with special
43
+ instructions for:
37
44
 
38
- ⚠️ If you were using an older version via a CDN, please update the entire url.
39
- The old URL will no longer work in a future release.
45
+ | [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) |
46
+ | --- | --- | --- | --- | --- | --- |
40
47
 
41
- That’s it. The script works in most browsers.
48
+ ## Options
42
49
 
43
- ## How it works
50
+ ### preserve
44
51
 
45
- The [PostCSS plugin](README-POSTCSS.md) clones rules containing `:blank`,
46
- replacing them with an alternative `[blank]` selector.
52
+ The `preserve` option determines whether the original notation
53
+ is preserved. By default, it is preserved.
54
+
55
+ ```js
56
+ postcssBlankPseudo({ preserve: false })
57
+ ```
47
58
 
48
- ```css
59
+ ```pcss
49
60
  input:blank {
50
- background-color: yellow;
61
+ background-color: yellow;
51
62
  }
52
63
 
53
64
  /* becomes */
54
65
 
55
- input[blank] {
56
- background-color: yellow;
66
+ input[blank].js-blank-pseudo, .js-blank-pseudo input[blank] {
67
+ background-color: yellow;
57
68
  }
69
+ ```
70
+
71
+ ### replaceWith
72
+
73
+ The `replaceWith` option determines the selector to use when replacing
74
+ the `:blank` pseudo. By default is `[blank]`
75
+
76
+ ```js
77
+ postcssBlankPseudo({ replaceWith: '.css-blank' })
78
+ ```
58
79
 
80
+ ```pcss
59
81
  input:blank {
60
- background-color: yellow;
82
+ background-color: yellow;
61
83
  }
84
+
85
+ /* becomes */
86
+
87
+ .foo {
88
+ color: blue;
89
+ color: red;
90
+ }
91
+
92
+ .baz {
93
+ color: green;
94
+ }
95
+ ```
96
+
97
+ Note that changing this option implies that it needs to be passed to the
98
+ browser polyfill as well.
99
+
100
+ ## Browser
101
+
102
+ ```js
103
+ import cssBlankPseudoInit from 'css-blank-pseudo/browser';
104
+
105
+ cssBlankPseudoInit();
62
106
  ```
63
107
 
64
- Next, the [JavaScript library](README-BROWSER.md) adds a `blank` attribute to
65
- elements otherwise matching `:blank` natively.
108
+ or
66
109
 
67
110
  ```html
68
- <input value="" blank>
69
- <input value="This element has a value">
111
+ <!-- When using a CDN url you will have to manually update the version number -->
112
+ <script src="https://unpkg.com/css-blank-pseudo@3.0.3/dist/browser-global.js"></script>
113
+ <script>cssBlankPseudoInit()</script>
70
114
  ```
71
115
 
72
- ## ⚠️ `:not(:blank)`
116
+ [PostCSS Blank Pseudo] works in all major browsers, including Safari 6+ and
117
+ Internet Explorer 9+ without any additional polyfills.
73
118
 
74
- with option : `preserve` `true`
119
+ This plugin conditionally uses `MutationObserver` to ensure recently inserted
120
+ inputs get correct styling upon insertion. If you intend to rely on that
121
+ behaviour for browsers that do not support `MutationObserver`, you have two
122
+ options:
75
123
 
76
- ```css
77
- input:not(:blank) {
78
- background-color: yellow;
79
- }
124
+ 1. Polyfill `MutationObserver`. As long as it runs before `cssBlankPseudoInit`,
125
+ the polyfill will work.
126
+ 2. If you don't want to polyfill `MutationObserver` you can also manually fire
127
+ a `change` event upon insertion so they're automatically inspected by the
128
+ polyfill.
80
129
 
81
- /* becomes */
130
+ ### Browser Usage
82
131
 
83
- input:not([blank]) {
84
- background-color: yellow;
85
- }
132
+ #### force
86
133
 
87
- input:not(:blank) {
88
- background-color: yellow;
89
- }
134
+ The `force` option determines whether the library runs even if the browser
135
+ supports the selector or not. By default, it won't run if the browser does
136
+ support the selector.
137
+
138
+ ```js
139
+ cssBlankPseudoInit({ force: true });
90
140
  ```
91
141
 
92
- When you do not include the JS polyfill one will always match in browsers that support `:blank` natively.
93
- In browsers that do not support `:blank` natively the rule will be invalid.
142
+ #### replaceWith
143
+
144
+ Similar to the option for the PostCSS Plugin, `replaceWith` determines the
145
+ attribute or class to apply to an element when it's considered to be `:blank`.
94
146
 
95
- _currently no browsers support `:blank`_
147
+ ```js
148
+ cssBlankPseudoInit({ replaceWith: '.css-blank' });
149
+ ```
96
150
 
151
+ This option should be used if it was changed at PostCSS configuration level.
152
+ Please note that using a class, leverages `classList` under the hood which
153
+ might not be supported on some old browsers such as IE9, so you may need
154
+ to polyfill `classList` in those cases.
97
155
 
98
- [git-img]: https://img.shields.io/badge/support-chat-blue.svg
99
- [git-url]: https://gitter.im/postcss/postcss
100
- [npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
156
+ [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
157
+ [css-url]: https://cssdb.org/#blank-pseudo-class
158
+ [discord]: https://discord.gg/bUadyRwkJS
101
159
  [npm-url]: https://www.npmjs.com/package/css-blank-pseudo
102
160
 
103
- [CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
104
- [PostCSS Preset Env]: https://preset-env.cssdb.org/
105
- [Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
161
+ [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
162
+ [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
163
+ [PostCSS]: https://github.com/postcss/postcss
164
+ [PostCSS Loader]: https://github.com/postcss/postcss-loader
165
+ [PostCSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
166
+ [Selectors Level 4]: https://www.w3.org/TR/selectors-4/#blank
@@ -1,125 +1,2 @@
1
- (function () {
2
-
3
- /* global MutationObserver */
4
- function cssBlankPseudo(document, opts) {
5
- // configuration
6
- var className = Object(opts).className;
7
- var attr = Object(opts).attr || 'blank';
8
- var force = Object(opts).force;
9
-
10
- try {
11
- document.querySelector(':blank');
12
-
13
- if (!force) {
14
- return;
15
- }
16
- } catch (ignoredError) {
17
- /* do nothing and continue */
18
- } // observe value changes on <input>, <select>, and <textarea>
19
-
20
-
21
- var window = (document.ownerDocument || document).defaultView;
22
- observeValueOfHTMLElement(window.HTMLInputElement);
23
- observeValueOfHTMLElement(window.HTMLSelectElement);
24
- observeValueOfHTMLElement(window.HTMLTextAreaElement);
25
- observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
26
-
27
- var selector = 'INPUT,SELECT,TEXTAREA';
28
- var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
29
-
30
- Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) {
31
- if (node.nodeName === 'SELECT') {
32
- node.addEventListener('change', configureCssBlankAttribute);
33
- } else {
34
- node.addEventListener('input', configureCssBlankAttribute);
35
- }
36
-
37
- configureCssBlankAttribute.call(node);
38
- }); // conditionally observe added or unobserve removed form control elements
39
-
40
- new MutationObserver(function (mutationsList) {
41
- mutationsList.forEach(function (mutation) {
42
- Array.prototype.forEach.call(mutation.addedNodes || [], function (node) {
43
- if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
44
- if (node.nodeName === 'SELECT') {
45
- node.addEventListener('change', configureCssBlankAttribute);
46
- } else {
47
- node.addEventListener('input', configureCssBlankAttribute);
48
- }
49
-
50
- configureCssBlankAttribute.call(node);
51
- }
52
- });
53
- Array.prototype.forEach.call(mutation.removedNodes || [], function (node) {
54
- if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
55
- if (node.nodeName === 'SELECT') {
56
- node.removeEventListener('change', configureCssBlankAttribute);
57
- } else {
58
- node.removeEventListener('input', configureCssBlankAttribute);
59
- }
60
- }
61
- });
62
- });
63
- }).observe(document, {
64
- childList: true,
65
- subtree: true
66
- }); // update a form control element’s css-blank attribute
67
-
68
- function configureCssBlankAttribute() {
69
- if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) {
70
- if (attr) {
71
- this.removeAttribute(attr);
72
- }
73
-
74
- if (className) {
75
- this.classList.remove(className);
76
- }
77
-
78
- this.removeAttribute('blank');
79
- } else {
80
- if (attr) {
81
- this.setAttribute('blank', attr);
82
- }
83
-
84
- if (className) {
85
- this.classList.add(className);
86
- }
87
- }
88
- } // observe changes to the "value" property on an HTML Element
89
-
90
-
91
- function observeValueOfHTMLElement(HTMLElement) {
92
- var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
93
- var nativeSet = descriptor.set;
94
-
95
- descriptor.set = function set(value) {
96
- // eslint-disable-line no-unused-vars
97
- nativeSet.apply(this, arguments);
98
- configureCssBlankAttribute.apply(this);
99
- };
100
-
101
- Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
102
- } // observe changes to the "selected" property on an HTML Element
103
-
104
-
105
- function observeSelectedOfHTMLElement(HTMLElement) {
106
- var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
107
- var nativeSet = descriptor.set;
108
-
109
- descriptor.set = function set(value) {
110
- // eslint-disable-line no-unused-vars
111
- nativeSet.apply(this, arguments);
112
- var event = document.createEvent('Event');
113
- event.initEvent('change', true, true);
114
- this.dispatchEvent(event);
115
- };
116
-
117
- Object.defineProperty(HTMLElement.prototype, 'selected', descriptor);
118
- }
119
- }
120
-
121
- /* global self */
122
- self.cssBlankPseudo = cssBlankPseudo;
123
-
124
- })();
1
+ !function(){var e=[" ",">","~",":","+","@","#","(",")"];var t="js-blank-pseudo";function n(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function r(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function o(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}self.cssBlankPseudoInit=function(c){var i={force:!1,replaceWith:"[blank]"};if(void 0!==c&&"force"in c&&(i.force=c.force),void 0!==c&&"replaceWith"in c&&(i.replaceWith=c.replaceWith),!function(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}(i.replaceWith))throw new Error(i.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!i.force)return}catch(e){}var a,d,l,u,s,f,p,v=("."===(a=i.replaceWith)[0]?(d=a.slice(1),l=function(e){return e.classList.remove(d)},u=function(e){return e.classList.add(d)}):(d=a.slice(1,-1),l=function(e){return e.removeAttribute(d,"")},u=function(e){return e.setAttribute(d,"")}),function(e){var t=e.target;n(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex].value:t.value)?l(t):u(t))}),m=function(){document.body&&(document.body.addEventListener("change",v),document.body.addEventListener("input",v))},E=function(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){v({target:e})}))};if(document.body?m():window.addEventListener("load",m),-1===document.documentElement.className.indexOf(t)&&(document.documentElement.className+=" js-blank-pseudo"),o(self.HTMLInputElement,v),o(self.HTMLSelectElement,v),o(self.HTMLTextAreaElement,v),s=self.HTMLOptionElement,f=Object.getOwnPropertyDescriptor(s.prototype,"selected"),p=f.set,f.set=function(e){p.apply(this,arguments);var t=r("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(s.prototype,"selected",f),E(),void 0!==self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&n(e)&&v({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var y=function(){return E()};window.addEventListener("load",y),window.addEventListener("DOMContentLoaded",y)}}}();
125
2
  //# sourceMappingURL=browser-global.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-global.js","sources":["../src/browser.js","../src/browser-global.js"],"sourcesContent":["/* global MutationObserver */\nexport default function cssBlankPseudo(document, opts) {\n\t// configuration\n\tconst className = Object(opts).className;\n\tconst attr = Object(opts).attr || 'blank';\n\tconst force = Object(opts).force;\n\n\ttry {\n\t\tdocument.querySelector(':blank');\n\n\t\tif (!force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\t// observe value changes on <input>, <select>, and <textarea>\n\tconst window = (document.ownerDocument || document).defaultView;\n\n\tobserveValueOfHTMLElement(window.HTMLInputElement);\n\tobserveValueOfHTMLElement(window.HTMLSelectElement);\n\tobserveValueOfHTMLElement(window.HTMLTextAreaElement);\n\tobserveSelectedOfHTMLElement(window.HTMLOptionElement);\n\n\t// form control elements selector\n\tconst selector = 'INPUT,SELECT,TEXTAREA';\n\tconst selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/;\n\n\t// conditionally update all form control elements\n\tArray.prototype.forEach.call(\n\t\tdocument.querySelectorAll(selector),\n\t\tnode => {\n\t\t\tif (node.nodeName === 'SELECT') {\n\t\t\t\tnode.addEventListener('change', configureCssBlankAttribute);\n\t\t\t} else {\n\t\t\t\tnode.addEventListener('input', configureCssBlankAttribute);\n\t\t\t}\n\n\t\t\tconfigureCssBlankAttribute.call(node);\n\t\t},\n\t);\n\n\t// conditionally observe added or unobserve removed form control elements\n\tnew MutationObserver(mutationsList => {\n\t\tmutationsList.forEach(mutation => {\n\t\t\tArray.prototype.forEach.call(\n\t\t\t\tmutation.addedNodes || [],\n\t\t\t\tnode => {\n\t\t\t\t\tif (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {\n\t\t\t\t\t\tif (node.nodeName === 'SELECT') {\n\t\t\t\t\t\t\tnode.addEventListener('change', configureCssBlankAttribute);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.addEventListener('input', configureCssBlankAttribute);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconfigureCssBlankAttribute.call(node);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tArray.prototype.forEach.call(\n\t\t\t\tmutation.removedNodes || [],\n\t\t\t\tnode => {\n\t\t\t\t\tif (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {\n\t\t\t\t\t\tif (node.nodeName === 'SELECT') {\n\t\t\t\t\t\t\tnode.removeEventListener('change', configureCssBlankAttribute);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.removeEventListener('input', configureCssBlankAttribute);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}).observe(document, { childList: true, subtree: true });\n\n\t// update a form control element’s css-blank attribute\n\tfunction configureCssBlankAttribute () {\n\t\tif (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) {\n\t\t\tif (attr) {\n\t\t\t\tthis.removeAttribute(attr);\n\t\t\t}\n\n\t\t\tif (className) {\n\t\t\t\tthis.classList.remove(className);\n\t\t\t}\n\t\t\tthis.removeAttribute('blank');\n\t\t} else {\n\t\t\tif (attr) {\n\t\t\t\tthis.setAttribute('blank', attr);\n\t\t\t}\n\n\t\t\tif (className) {\n\t\t\t\tthis.classList.add(className);\n\t\t\t}\n\t\t}\n\t}\n\n\t// observe changes to the \"value\" property on an HTML Element\n\tfunction observeValueOfHTMLElement (HTMLElement) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\t\tconst nativeSet = descriptor.set;\n\n\t\tdescriptor.set = function set (value) { // eslint-disable-line no-unused-vars\n\t\t\tnativeSet.apply(this, arguments);\n\n\t\t\tconfigureCssBlankAttribute.apply(this);\n\t\t};\n\n\t\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n\t}\n\n\t// observe changes to the \"selected\" property on an HTML Element\n\tfunction observeSelectedOfHTMLElement (HTMLElement) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\t\tconst nativeSet = descriptor.set;\n\n\t\tdescriptor.set = function set (value) { // eslint-disable-line no-unused-vars\n\t\t\tnativeSet.apply(this, arguments);\n\n\t\t\tconst event = document.createEvent('Event');\n\t\t\tevent.initEvent('change', true, true);\n\t\t\tthis.dispatchEvent(event);\n\t\t};\n\n\t\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n\t}\n}\n","/* global self */\nimport { default as cssBlankPseudo } from './browser';\nself.cssBlankPseudo = cssBlankPseudo;\n"],"names":["cssBlankPseudo","document","opts","className","Object","attr","force","querySelector","ignoredError","window","ownerDocument","defaultView","observeValueOfHTMLElement","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","observeSelectedOfHTMLElement","HTMLOptionElement","selector","selectorRegExp","Array","prototype","forEach","call","querySelectorAll","node","nodeName","addEventListener","configureCssBlankAttribute","MutationObserver","mutationsList","mutation","addedNodes","nodeType","test","removedNodes","removeEventListener","observe","childList","subtree","value","options","selectedIndex","removeAttribute","classList","remove","setAttribute","add","HTMLElement","descriptor","getOwnPropertyDescriptor","nativeSet","set","apply","arguments","defineProperty","event","createEvent","initEvent","dispatchEvent","self"],"mappings":";;CAAA;CACe,SAASA,cAAT,CAAwBC,QAAxB,EAAkCC,IAAlC,EAAwC;CACtD;CACA,MAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;CACA,MAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;CACA,MAAMC,KAAK,GAAGF,MAAM,CAACF,IAAD,CAAN,CAAaI,KAA3B;;CAEA,MAAI;CACHL,IAAAA,QAAQ,CAACM,aAAT,CAAuB,QAAvB;;CAEA,QAAI,CAACD,KAAL,EAAY;CACX;CACA;CACD,GAND,CAME,OAAOE,YAAP,EAAqB;CAAE;CAA+B,GAZF;;;CAetD,MAAMC,MAAM,GAAG,CAACR,QAAQ,CAACS,aAAT,IAA0BT,QAA3B,EAAqCU,WAApD;CAEAC,EAAAA,yBAAyB,CAACH,MAAM,CAACI,gBAAR,CAAzB;CACAD,EAAAA,yBAAyB,CAACH,MAAM,CAACK,iBAAR,CAAzB;CACAF,EAAAA,yBAAyB,CAACH,MAAM,CAACM,mBAAR,CAAzB;CACAC,EAAAA,4BAA4B,CAACP,MAAM,CAACQ,iBAAR,CAA5B,CApBsD;;CAuBtD,MAAMC,QAAQ,GAAG,uBAAjB;CACA,MAAMC,cAAc,GAAG,2BAAvB,CAxBs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E;CACvCW,MAAAA,SAAS,CAACE,KAAV,CAAgB,IAAhB,EAAsBC,SAAtB;CAEA1B,MAAAA,0BAA0B,CAACyB,KAA3B,CAAiC,IAAjC;CACA,KAJD;;CAMAjD,IAAAA,MAAM,CAACmD,cAAP,CAAsBP,WAAW,CAAC3B,SAAlC,EAA6C,OAA7C,EAAsD4B,UAAtD;CACA,GA3GqD;;;CA8GtD,WAASjC,4BAAT,CAAuCgC,WAAvC,EAAoD;CACnD,QAAMC,UAAU,GAAG7C,MAAM,CAAC8C,wBAAP,CAAgCF,WAAW,CAAC3B,SAA5C,EAAuD,UAAvD,CAAnB;CACA,QAAM8B,SAAS,GAAGF,UAAU,CAACG,GAA7B;;CAEAH,IAAAA,UAAU,CAACG,GAAX,GAAiB,SAASA,GAAT,CAAcZ,KAAd,EAAqB;CAAE;CACvCW,MAAAA,SAAS,CAACE,KAAV,CAAgB,IAAhB,EAAsBC,SAAtB;CAEA,UAAME,KAAK,GAAGvD,QAAQ,CAACwD,WAAT,CAAqB,OAArB,CAAd;CACAD,MAAAA,KAAK,CAACE,SAAN,CAAgB,QAAhB,EAA0B,IAA1B,EAAgC,IAAhC;CACA,WAAKC,aAAL,CAAmBH,KAAnB;CACA,KAND;;CAQApD,IAAAA,MAAM,CAACmD,cAAP,CAAsBP,WAAW,CAAC3B,SAAlC,EAA6C,UAA7C,EAAyD4B,UAAzD;CACA;CACD;;CC7HD;CAEAW,IAAI,CAAC5D,cAAL,GAAsBA,cAAtB;;;;;;"}
1
+ {"version":3,"file":"browser-global.js","sources":["../src/is-valid-replacement.mjs","../src/browser.js","../src/browser-global.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = (el) => el.classList.remove(selector);\n\t\tadd = (el) => el.classList.add(selector);\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\t\tremove = (el) => el.removeAttribute(selector, '');\n\t\tadd = (el) => el.setAttribute(selector, '');\n\t}\n\n\treturn function handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\n\t};\n\n\tif (typeof opts !== 'undefined' && 'force' in opts) {\n\t\toptions.force = opts.force;\n\t}\n\n\tif (typeof opts !== 'undefined' && 'replaceWith' in opts) {\n\t\toptions.replaceWith = opts.replaceWith;\n\t}\n\n\tif (!isValidReplacement(options.replaceWith)) {\n\t\tthrow new Error(`${options.replaceWith} is not a valid replacement since it can't be applied to single elements.`);\n\t}\n\n\ttry {\n\t\tdocument.querySelector(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n","/* global self */\nimport { default as cssBlankPseudoInit } from './browser';\nself.cssBlankPseudoInit = cssBlankPseudoInit;\n"],"names":["INVALID_SELECTOR_CHAR","CSS_CLASS_LOADED","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","self","cssBlankPseudoInit","opts","options","force","replaceWith","selector","isValid","i","length","indexOf","isValidReplacement","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"mappings":"YAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,KCND,IAAMC,EAAmB,kBAGzB,SAASC,EAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,SAO9E,SAASC,EAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAXC,MACVD,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,EAsDR,SAASM,EAA0BC,EAAaC,GAC/C,IAAMC,EAAaC,OAAOC,yBAAyBJ,EAAYK,UAAW,SACpEC,EAAYJ,EAAWK,IAE7BL,EAAWK,IAAM,WAChBD,EAAUE,MAAMC,KAAMC,WACtBT,EAAQ,CAAEU,OAAQF,QAGnBN,OAAOS,eAAeZ,EAAYK,UAAW,QAASH,GCrFvDW,KAAKC,mBDwFU,SAA4BC,GAE1C,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,WAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,cD1Fd,SAA4BC,GAI1C,IAHA,IAAIC,GAAU,EAGLC,EAAI,EAAGC,EAASpC,EAAsBoC,OAAQD,EAAIC,GAAUF,EAASC,IACzEF,EAASI,QAAQrC,EAAsBmC,KAAO,IACjDD,GAAU,GAIZ,OAAOA,ECmFFI,CAAmBR,EAAQE,aAC/B,MAAM,IAAIO,MAAST,EAAQE,YAA3B,6EAGD,IAGC,GAFAtB,SAAS8B,cAAc,WAElBV,EAAQC,MACZ,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B,EAAQF,EAAe,UAC7BkB,KAAK4C,cAAcC,cAAc7D,IAGlCU,OAAOS,eAAeZ,EAAYK,UAAW,WAAYH,GA2EzDsC,SAEqC,IAA1B3B,KAAK0C,iBAEf,IAAIA,kBAAiB,SAAAC,GACpBA,EAAcd,SAAQ,SAAAe,GACrBhB,MAAMpC,UAAUqC,QAAQC,KACvBc,EAASC,YAAc,IACvB,SAAAb,GACuB,IAAlBA,EAAKc,UAAkBvE,EAAqByD,IAC/C5C,EAAQ,CAAEU,OAAQkC,aAKpBe,QAAQhE,SAAU,CAAEiE,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,WAAA,OAAMvB,KAE3BM,OAAOP,iBAAiB,OAAQwB,GAChCjB,OAAOP,iBAAiB,mBAAoBwB"}
package/dist/browser.cjs CHANGED
@@ -1,120 +1,2 @@
1
- /* global MutationObserver */
2
- function cssBlankPseudo(document, opts) {
3
- // configuration
4
- var className = Object(opts).className;
5
- var attr = Object(opts).attr || 'blank';
6
- var force = Object(opts).force;
7
-
8
- try {
9
- document.querySelector(':blank');
10
-
11
- if (!force) {
12
- return;
13
- }
14
- } catch (ignoredError) {
15
- /* do nothing and continue */
16
- } // observe value changes on <input>, <select>, and <textarea>
17
-
18
-
19
- var window = (document.ownerDocument || document).defaultView;
20
- observeValueOfHTMLElement(window.HTMLInputElement);
21
- observeValueOfHTMLElement(window.HTMLSelectElement);
22
- observeValueOfHTMLElement(window.HTMLTextAreaElement);
23
- observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
24
-
25
- var selector = 'INPUT,SELECT,TEXTAREA';
26
- var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
27
-
28
- Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) {
29
- if (node.nodeName === 'SELECT') {
30
- node.addEventListener('change', configureCssBlankAttribute);
31
- } else {
32
- node.addEventListener('input', configureCssBlankAttribute);
33
- }
34
-
35
- configureCssBlankAttribute.call(node);
36
- }); // conditionally observe added or unobserve removed form control elements
37
-
38
- new MutationObserver(function (mutationsList) {
39
- mutationsList.forEach(function (mutation) {
40
- Array.prototype.forEach.call(mutation.addedNodes || [], function (node) {
41
- if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
42
- if (node.nodeName === 'SELECT') {
43
- node.addEventListener('change', configureCssBlankAttribute);
44
- } else {
45
- node.addEventListener('input', configureCssBlankAttribute);
46
- }
47
-
48
- configureCssBlankAttribute.call(node);
49
- }
50
- });
51
- Array.prototype.forEach.call(mutation.removedNodes || [], function (node) {
52
- if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
53
- if (node.nodeName === 'SELECT') {
54
- node.removeEventListener('change', configureCssBlankAttribute);
55
- } else {
56
- node.removeEventListener('input', configureCssBlankAttribute);
57
- }
58
- }
59
- });
60
- });
61
- }).observe(document, {
62
- childList: true,
63
- subtree: true
64
- }); // update a form control element’s css-blank attribute
65
-
66
- function configureCssBlankAttribute() {
67
- if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) {
68
- if (attr) {
69
- this.removeAttribute(attr);
70
- }
71
-
72
- if (className) {
73
- this.classList.remove(className);
74
- }
75
-
76
- this.removeAttribute('blank');
77
- } else {
78
- if (attr) {
79
- this.setAttribute('blank', attr);
80
- }
81
-
82
- if (className) {
83
- this.classList.add(className);
84
- }
85
- }
86
- } // observe changes to the "value" property on an HTML Element
87
-
88
-
89
- function observeValueOfHTMLElement(HTMLElement) {
90
- var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
91
- var nativeSet = descriptor.set;
92
-
93
- descriptor.set = function set(value) {
94
- // eslint-disable-line no-unused-vars
95
- nativeSet.apply(this, arguments);
96
- configureCssBlankAttribute.apply(this);
97
- };
98
-
99
- Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
100
- } // observe changes to the "selected" property on an HTML Element
101
-
102
-
103
- function observeSelectedOfHTMLElement(HTMLElement) {
104
- var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
105
- var nativeSet = descriptor.set;
106
-
107
- descriptor.set = function set(value) {
108
- // eslint-disable-line no-unused-vars
109
- nativeSet.apply(this, arguments);
110
- var event = document.createEvent('Event');
111
- event.initEvent('change', true, true);
112
- this.dispatchEvent(event);
113
- };
114
-
115
- Object.defineProperty(HTMLElement.prototype, 'selected', descriptor);
116
- }
117
- }
118
-
119
- module.exports = cssBlankPseudo;
1
+ var e=[" ",">","~",":","+","@","#","(",")"];function t(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function n(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function r(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}module.exports=function(o){var c={force:!1,replaceWith:"[blank]"};if(void 0!==o&&"force"in o&&(c.force=o.force),void 0!==o&&"replaceWith"in o&&(c.replaceWith=o.replaceWith),!function(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}(c.replaceWith))throw new Error(c.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!c.force)return}catch(e){}var i,a,d,l,u,s,p,f=("."===(i=c.replaceWith)[0]?(a=i.slice(1),d=function(e){return e.classList.remove(a)},l=function(e){return e.classList.add(a)}):(a=i.slice(1,-1),d=function(e){return e.removeAttribute(a,"")},l=function(e){return e.setAttribute(a,"")}),function(e){var n=e.target;t(n)&&(("SELECT"===n.nodeName?n.options[n.selectedIndex].value:n.value)?d(n):l(n))}),v=function(){document.body&&(document.body.addEventListener("change",f),document.body.addEventListener("input",f))},m=function(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){f({target:e})}))};if(document.body?v():window.addEventListener("load",v),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),r(self.HTMLInputElement,f),r(self.HTMLSelectElement,f),r(self.HTMLTextAreaElement,f),u=self.HTMLOptionElement,s=Object.getOwnPropertyDescriptor(u.prototype,"selected"),p=s.set,s.set=function(e){p.apply(this,arguments);var t=n("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(u.prototype,"selected",s),m(),void 0!==self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&t(e)&&f({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var E=function(){return m()};window.addEventListener("load",E),window.addEventListener("DOMContentLoaded",E)}};
120
2
  //# sourceMappingURL=browser.cjs.map