css-blank-pseudo 2.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/LICENSE.md ADDED
@@ -0,0 +1,108 @@
1
+ # CC0 1.0 Universal
2
+
3
+ ## Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an “owner”) of an original work of
8
+ authorship and/or a database (each, a “Work”).
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific works
12
+ (“Commons”) that the public can reliably and without fear of later claims of
13
+ infringement build upon, modify, incorporate in other works, reuse and
14
+ redistribute as freely as possible in any form whatsoever and for any purposes,
15
+ including without limitation commercial purposes. These owners may contribute
16
+ to the Commons to promote the ideal of a free culture and the further
17
+ production of creative, cultural and scientific works, or to gain reputation or
18
+ greater distribution for their Work in part through the use and efforts of
19
+ others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation of
22
+ additional consideration or compensation, the person associating CC0 with a
23
+ Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
25
+ publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights (“Copyright and
31
+ Related Rights”). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+ 1. the right to reproduce, adapt, distribute, perform, display, communicate,
34
+ and translate a Work;
35
+ 2. moral rights retained by the original author(s) and/or performer(s);
36
+ 3. publicity and privacy rights pertaining to a person’s image or likeness
37
+ depicted in a Work;
38
+ 4. rights protecting against unfair competition in regards to a Work,
39
+ subject to the limitations in paragraph 4(i), below;
40
+ 5. rights protecting the extraction, dissemination, use and reuse of data in
41
+ a Work;
42
+ 6. database rights (such as those arising under Directive 96/9/EC of the
43
+ European Parliament and of the Council of 11 March 1996 on the legal
44
+ protection of databases, and under any national implementation thereof,
45
+ including any amended or successor version of such directive); and
46
+ 7. other similar, equivalent or corresponding rights throughout the world
47
+ based on applicable law or treaty, and any national implementations
48
+ thereof.
49
+
50
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
51
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
52
+ unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
53
+ and Related Rights and associated claims and causes of action, whether now
54
+ known or unknown (including existing as well as future claims and causes of
55
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
56
+ duration provided by applicable law or treaty (including future time
57
+ extensions), (iii) in any current or future medium and for any number of
58
+ copies, and (iv) for any purpose whatsoever, including without limitation
59
+ commercial, advertising or promotional purposes (the “Waiver”). Affirmer
60
+ makes the Waiver for the benefit of each member of the public at large and
61
+ to the detriment of Affirmer’s heirs and successors, fully intending that
62
+ such Waiver shall not be subject to revocation, rescission, cancellation,
63
+ termination, or any other legal or equitable action to disrupt the quiet
64
+ enjoyment of the Work by the public as contemplated by Affirmer’s express
65
+ Statement of Purpose.
66
+
67
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
68
+ judged legally invalid or ineffective under applicable law, then the Waiver
69
+ shall be preserved to the maximum extent permitted taking into account
70
+ Affirmer’s express Statement of Purpose. In addition, to the extent the
71
+ Waiver is so judged Affirmer hereby grants to each affected person a
72
+ royalty-free, non transferable, non sublicensable, non exclusive,
73
+ irrevocable and unconditional license to exercise Affirmer’s Copyright and
74
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
75
+ maximum duration provided by applicable law or treaty (including future time
76
+ extensions), (iii) in any current or future medium and for any number of
77
+ copies, and (iv) for any purpose whatsoever, including without limitation
78
+ commercial, advertising or promotional purposes (the “License”). The License
79
+ shall be deemed effective as of the date CC0 was applied by Affirmer to the
80
+ Work. Should any part of the License for any reason be judged legally
81
+ invalid or ineffective under applicable law, such partial invalidity or
82
+ ineffectiveness shall not invalidate the remainder of the License, and in
83
+ such case Affirmer hereby affirms that he or she will not (i) exercise any
84
+ of his or her remaining Copyright and Related Rights in the Work or (ii)
85
+ assert any associated claims and causes of action with respect to the Work,
86
+ in either case contrary to Affirmer’s express Statement of Purpose.
87
+
88
+ 4. Limitations and Disclaimers.
89
+ 1. No trademark or patent rights held by Affirmer are waived, abandoned,
90
+ surrendered, licensed or otherwise affected by this document.
91
+ 2. Affirmer offers the Work as-is and makes no representations or warranties
92
+ of any kind concerning the Work, express, implied, statutory or
93
+ otherwise, including without limitation warranties of title,
94
+ merchantability, fitness for a particular purpose, non infringement, or
95
+ the absence of latent or other defects, accuracy, or the present or
96
+ absence of errors, whether or not discoverable, all to the greatest
97
+ extent permissible under applicable law.
98
+ 3. Affirmer disclaims responsibility for clearing rights of other persons
99
+ that may apply to the Work or any use thereof, including without
100
+ limitation any person’s Copyright and Related Rights in the Work.
101
+ Further, Affirmer disclaims responsibility for obtaining any necessary
102
+ consents, permissions or other rights required for any use of the Work.
103
+ 4. Affirmer understands and acknowledges that Creative Commons is not a
104
+ party to this document and has no duty or obligation with respect to this
105
+ CC0 or use of the Work.
106
+
107
+ For more information, please see
108
+ http://creativecommons.org/publicdomain/zero/1.0/.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # CSS Blank Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Blank Pseudo]
2
+
3
+ [![NPM Version][npm-img]][npm-url]
4
+ [![Build Status][cli-img]][cli-url]
5
+ [![Support Chat][git-img]][git-url]
6
+
7
+ [CSS Blank Pseudo] lets you style form elements when they are empty, following
8
+ the [Selectors Level 4] specification.
9
+
10
+ ```css
11
+ input {
12
+ /* style an input */
13
+ }
14
+
15
+ input:blank {
16
+ /* style an input without a value */
17
+ }
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ From the command line, transform CSS files that use `:blank` selectors:
23
+
24
+ ```bash
25
+ npx css-blank-pseudo SOURCE.css TRANSFORMED.css
26
+ ```
27
+
28
+ Next, use your transformed CSS with this script:
29
+
30
+ ```html
31
+ <link rel="stylesheet" href="TRANSFORMED.css">
32
+ <script src="https://unpkg.com/css-blank-pseudo/browser"></script>
33
+ <script>cssBlankPseudo(document)</script>
34
+ ```
35
+
36
+ That’s it. The script is 509 bytes and works in all browsers.
37
+
38
+ ---
39
+
40
+ If you support Internet Explorer 11, use the **browser legacy** script, which
41
+ is 671 bytes:
42
+
43
+ ```html
44
+ <link rel="stylesheet" href="TRANSFORMED.css">
45
+ <script src="https://unpkg.com/css-blank-pseudo/browser-legacy"></script>
46
+ <script>cssBlankPseudo(document)</script>
47
+ ```
48
+
49
+ ## How it works
50
+
51
+ The [PostCSS plugin](README-POSTCSS.md) clones rules containing `:blank`,
52
+ replacing them with an alternative `[blank]` selector.
53
+
54
+ ```css
55
+ input:blank {
56
+ background-color: yellow;
57
+ }
58
+
59
+ /* becomes */
60
+
61
+ input[blank] {
62
+ background-color: yellow;
63
+ }
64
+
65
+ input:blank {
66
+ background-color: yellow;
67
+ }
68
+ ```
69
+
70
+ Next, the [JavaScript library](README-BROWSER.md) adds a `blank` attribute to
71
+ elements otherwise matching `:blank` natively.
72
+
73
+ ```html
74
+ <input value="" blank>
75
+ <input value="This element has a value">
76
+ ```
77
+
78
+ [cli-img]: https://img.shields.io/travis/csstools/css-blank-pseudo/master.svg
79
+ [cli-url]: https://travis-ci.org/csstools/css-blank-pseudo
80
+ [git-img]: https://img.shields.io/badge/support-chat-blue.svg
81
+ [git-url]: https://gitter.im/postcss/postcss
82
+ [npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
83
+ [npm-url]: https://www.npmjs.com/package/css-blank-pseudo
84
+
85
+ [CSS Blank Pseudo]: https://github.com/csstools/css-blank-pseudo
86
+ [PostCSS Preset Env]: https://preset-env.cssdb.org/
87
+ [Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=browser-legacy.js.map
package/browser.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=browser.js.map
package/cli.js ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+
3
+ var fs = require('fs');
4
+
5
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
+
7
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
8
+
9
+ const selectorRegExp = /:blank([^\w-]|$)/gi;
10
+
11
+ const creator = opts => {
12
+ const replaceWith = String(Object(opts).replaceWith || '[blank]');
13
+ const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
14
+ return {
15
+ postcssPlugin: 'css-blank-pseudo',
16
+ Once: root => {
17
+ root.walkRules(selectorRegExp, rule => {
18
+ const selector = rule.selector.replace(selectorRegExp, ($0, $1) => {
19
+ return `${replaceWith}${$1}`;
20
+ });
21
+ const clone = rule.clone({
22
+ selector
23
+ });
24
+
25
+ if (preserve) {
26
+ rule.before(clone);
27
+ } else {
28
+ rule.replaceWith(clone);
29
+ }
30
+ });
31
+ }
32
+ };
33
+ };
34
+
35
+ creator.postcss = true;
36
+
37
+ if (process.argv.length < 3) {
38
+ console.log(['CSS Blank Pseudo\n', ' Transforms CSS with :blank {}\n', 'Usage:\n', ' css-blank-pseudo source.css transformed.css', ' css-blank-pseudo --in=source.css --out=transformed.css --opts={}', ' echo "@media (prefers-color-scheme: dark) {}" | css-blank-pseudo\n'].join('\n'));
39
+ process.exit(0);
40
+ } // get process and plugin options from the command line
41
+
42
+
43
+ const fileRegExp = /^[\w/.]+$/;
44
+ const argRegExp = /^--(\w+)=("|')?(.+)\2$/;
45
+ const relaxedJsonPropRegExp = /(['"])?([a-z0-9A-Z_]+)(['"])?:/g;
46
+ const relaxedJsonValueRegExp = /("[a-z0-9A-Z_]+":\s*)'?([A-z0-9]+)'?([,}])/g;
47
+ const argo = process.argv.slice(2).reduce((object, arg) => {
48
+ const argMatch = arg.match(argRegExp);
49
+ const fileMatch = arg.match(fileRegExp);
50
+
51
+ if (argMatch) {
52
+ object[argMatch[1]] = argMatch[3];
53
+ } else if (fileMatch) {
54
+ if (object.from === '<stdin>') {
55
+ object.from = arg;
56
+ } else if (object.to === '<stdout>') {
57
+ object.to = arg;
58
+ }
59
+ }
60
+
61
+ return object;
62
+ }, {
63
+ from: '<stdin>',
64
+ to: '<stdout>',
65
+ opts: 'null'
66
+ }); // get css from command line arguments or stdin
67
+
68
+ (argo.from === '<stdin>' ? getStdin() : readFile(argo.from)).then(css => {
69
+ const pluginOpts = JSON.parse(argo.opts.replace(relaxedJsonPropRegExp, '"$2": ').replace(relaxedJsonValueRegExp, '$1"$2"$3'));
70
+ const processOptions = Object.assign({
71
+ from: argo.from,
72
+ to: argo.to || argo.from
73
+ }, argo.map ? {
74
+ map: JSON.parse(argo.map)
75
+ } : {});
76
+ const result = creator.process(css, processOptions, pluginOpts);
77
+
78
+ if (argo.to === '<stdout>') {
79
+ return result.css;
80
+ } else {
81
+ return writeFile(argo.to, result.css).then(() => `CSS was written to "${argo.to}"`);
82
+ }
83
+ }).then(result => {
84
+ console.log(result);
85
+ process.exit(0);
86
+ }, error => {
87
+ console.error(error);
88
+ process.exit(1);
89
+ });
90
+
91
+ function readFile(pathname) {
92
+ return new Promise((resolve, reject) => {
93
+ fs__default['default'].readFile(pathname, 'utf8', (error, data) => {
94
+ if (error) {
95
+ reject(error);
96
+ } else {
97
+ resolve(data);
98
+ }
99
+ });
100
+ });
101
+ }
102
+
103
+ function writeFile(pathname, data) {
104
+ return new Promise((resolve, reject) => {
105
+ fs__default['default'].writeFile(pathname, data, (error, content) => {
106
+ if (error) {
107
+ reject(error);
108
+ } else {
109
+ resolve(content);
110
+ }
111
+ });
112
+ });
113
+ }
114
+
115
+ function getStdin() {
116
+ return new Promise(resolve => {
117
+ let data = '';
118
+
119
+ if (process.stdin.isTTY) {
120
+ resolve(data);
121
+ } else {
122
+ process.stdin.setEncoding('utf8');
123
+ process.stdin.on('readable', () => {
124
+ let chunk;
125
+
126
+ while (chunk = process.stdin.read()) {
127
+ data += chunk;
128
+ }
129
+ });
130
+ process.stdin.on('end', () => {
131
+ resolve(data);
132
+ });
133
+ }
134
+ });
135
+ }
136
+ //# sourceMappingURL=cli.js.map
package/index.js ADDED
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ function cssBlankPseudo(document, opts) {
4
+ // configuration
5
+ const className = Object(opts).className;
6
+ const attr = Object(opts).attr || 'blank';
7
+ const force = Object(opts).force;
8
+
9
+ try {
10
+ document.querySelector(':blank');
11
+
12
+ if (!force) {
13
+ return;
14
+ }
15
+ } catch (ignoredError) {
16
+ /* do nothing and continue */
17
+ } // observe value changes on <input>, <select>, and <textarea>
18
+
19
+
20
+ const window = (document.ownerDocument || document).defaultView;
21
+ observeValueOfHTMLElement(window.HTMLInputElement);
22
+ observeValueOfHTMLElement(window.HTMLSelectElement);
23
+ observeValueOfHTMLElement(window.HTMLTextAreaElement); // form control elements selector
24
+
25
+ const selector = 'input,select,textarea'; // conditionally update all form control elements
26
+
27
+ Array.prototype.forEach.call(document.querySelectorAll(selector), node => {
28
+ node.addEventListener('input', configureCssBlankAttribute);
29
+ configureCssBlankAttribute.call(node);
30
+ }); // conditionally observe added or unobserve removed form control elements
31
+
32
+ new MutationObserver(mutationsList => {
33
+ mutationsList.forEach(mutation => {
34
+ if (mutation.addedNodes) {
35
+ mutation.addedNodes.forEach(node => {
36
+ if (node.nodeType === 1 && node.matches(selector)) {
37
+ node.addEventListener('input', configureCssBlankAttribute);
38
+ configureCssBlankAttribute.call(node);
39
+ }
40
+ });
41
+ }
42
+
43
+ if (mutation.removedNodes) {
44
+ mutation.removedNodes.forEach(node => {
45
+ if (node.nodeType === 1 && node.matches(selector)) {
46
+ node.removeEventListener('input', configureCssBlankAttribute);
47
+ }
48
+ });
49
+ }
50
+ });
51
+ }).observe(document, {
52
+ childList: true,
53
+ subtree: true
54
+ }); // update a form control element’s css-blank attribute
55
+
56
+ function configureCssBlankAttribute() {
57
+ if (this.value) {
58
+ if (attr) {
59
+ this.removeAttribute(attr);
60
+ }
61
+
62
+ if (className) {
63
+ this.classList.remove(className);
64
+ }
65
+
66
+ this.removeAttribute('blank');
67
+ } else {
68
+ if (attr) {
69
+ this.setAttribute('blank', attr);
70
+ }
71
+
72
+ if (className) {
73
+ this.classList.add(className);
74
+ }
75
+ }
76
+ } // observe changes to the "value" property on an HTML Element
77
+
78
+
79
+ function observeValueOfHTMLElement(HTMLElement) {
80
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
81
+ const nativeSet = descriptor.set;
82
+
83
+ descriptor.set = function set(value) {
84
+ // eslint-disable-line no-unused-vars
85
+ nativeSet.apply(this, arguments);
86
+ configureCssBlankAttribute.apply(this);
87
+ };
88
+
89
+ Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
90
+ }
91
+ }
92
+
93
+ module.exports = cssBlankPseudo;
94
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["src/browser.js"],"sourcesContent":["export 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\n\t// form control elements selector\n\tconst selector = '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\tnode.addEventListener('input', configureCssBlankAttribute);\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\tif (mutation.addedNodes) {\n\t\t\t\tmutation.addedNodes.forEach(\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && node.matches(selector)) {\n\t\t\t\t\t\t\tnode.addEventListener('input', configureCssBlankAttribute);\n\t\t\t\t\t\t\tconfigureCssBlankAttribute.call(node);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (mutation.removedNodes) {\n\t\t\t\tmutation.removedNodes.forEach(\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && node.matches(selector)) {\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) {\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"],"names":["cssBlankPseudo","document","opts","className","Object","attr","force","querySelector","ignoredError","window","ownerDocument","defaultView","observeValueOfHTMLElement","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","selector","Array","prototype","forEach","call","querySelectorAll","node","addEventListener","configureCssBlankAttribute","MutationObserver","mutationsList","mutation","addedNodes","nodeType","matches","removedNodes","removeEventListener","observe","childList","subtree","value","removeAttribute","classList","remove","setAttribute","add","HTMLElement","descriptor","getOwnPropertyDescriptor","nativeSet","set","apply","arguments","defineProperty"],"mappings":";;AAAe,SAASA,cAAT,CAAyBC,QAAzB,EAAmCC,IAAnC,EAAyC;AACvD;AACA,QAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;AACA,QAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;AACA,QAAMC,KAAK,GAAGF,MAAM,CAACF,IAAD,CAAN,CAAaI,KAA3B;;AAEA,MAAI;AACHL,IAAAA,QAAQ,CAACM,aAAT,CAAuB,QAAvB;;AAEA,QAAI,CAACD,KAAL,EAAY;AACX;AACA;AACD,GAND,CAME,OAAOE,YAAP,EAAqB;AAAE;AAA+B,GAZD;;;AAevD,QAAMC,MAAM,GAAG,CAACR,QAAQ,CAACS,aAAT,IAA0BT,QAA3B,EAAqCU,WAApD;AAEAC,EAAAA,yBAAyB,CAACH,MAAM,CAACI,gBAAR,CAAzB;AACAD,EAAAA,yBAAyB,CAACH,MAAM,CAACK,iBAAR,CAAzB;AACAF,EAAAA,yBAAyB,CAACH,MAAM,CAACM,mBAAR,CAAzB,CAnBuD;;AAsBvD,QAAMC,QAAQ,GAAG,uBAAjB,CAtBuD;;AAyBvDC,EAAAA,KAAK,CAACC,SAAN,CAAgBC,OAAhB,CAAwBC,IAAxB,CACCnB,QAAQ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AACd,aAAKmC,SAAL,CAAeC,MAAf,CAAsBpC,SAAtB;AACA;;AACD,WAAKkC,eAAL,CAAqB,OAArB;AACA,KATD,MASO;AACN,UAAIhC,IAAJ,EAAU;AACT,aAAKmC,YAAL,CAAkB,OAAlB,EAA2BnC,IAA3B;AACA;;AAED,UAAIF,SAAJ,EAAe;AACd,aAAKmC,SAAL,CAAeG,GAAf,CAAmBtC,SAAnB;AACA;AACD;AACD,GA/EsD;;;AAkFvD,WAASS,yBAAT,CAAoC8B,WAApC,EAAiD;AAChD,UAAMC,UAAU,GAAGvC,MAAM,CAACwC,wBAAP,CAAgCF,WAAW,CAACxB,SAA5C,EAAuD,OAAvD,CAAnB;AACA,UAAM2B,SAAS,GAAGF,UAAU,CAACG,GAA7B;;AAEAH,IAAAA,UAAU,CAACG,GAAX,GAAiB,SAASA,GAAT,CAAcV,KAAd,EAAqB;AAAE;AACvCS,MAAAA,SAAS,CAACE,KAAV,CAAgB,IAAhB,EAAsBC,SAAtB;AAEAxB,MAAAA,0BAA0B,CAACuB,KAA3B,CAAiC,IAAjC;AACA,KAJD;;AAMA3C,IAAAA,MAAM,CAAC6C,cAAP,CAAsBP,WAAW,CAACxB,SAAlC,EAA6C,OAA7C,EAAsDyB,UAAtD;AACA;AACD;;;;"}
package/index.mjs ADDED
@@ -0,0 +1,92 @@
1
+ function cssBlankPseudo(document, opts) {
2
+ // configuration
3
+ const className = Object(opts).className;
4
+ const attr = Object(opts).attr || 'blank';
5
+ const force = Object(opts).force;
6
+
7
+ try {
8
+ document.querySelector(':blank');
9
+
10
+ if (!force) {
11
+ return;
12
+ }
13
+ } catch (ignoredError) {
14
+ /* do nothing and continue */
15
+ } // observe value changes on <input>, <select>, and <textarea>
16
+
17
+
18
+ const window = (document.ownerDocument || document).defaultView;
19
+ observeValueOfHTMLElement(window.HTMLInputElement);
20
+ observeValueOfHTMLElement(window.HTMLSelectElement);
21
+ observeValueOfHTMLElement(window.HTMLTextAreaElement); // form control elements selector
22
+
23
+ const selector = 'input,select,textarea'; // conditionally update all form control elements
24
+
25
+ Array.prototype.forEach.call(document.querySelectorAll(selector), node => {
26
+ node.addEventListener('input', configureCssBlankAttribute);
27
+ configureCssBlankAttribute.call(node);
28
+ }); // conditionally observe added or unobserve removed form control elements
29
+
30
+ new MutationObserver(mutationsList => {
31
+ mutationsList.forEach(mutation => {
32
+ if (mutation.addedNodes) {
33
+ mutation.addedNodes.forEach(node => {
34
+ if (node.nodeType === 1 && node.matches(selector)) {
35
+ node.addEventListener('input', configureCssBlankAttribute);
36
+ configureCssBlankAttribute.call(node);
37
+ }
38
+ });
39
+ }
40
+
41
+ if (mutation.removedNodes) {
42
+ mutation.removedNodes.forEach(node => {
43
+ if (node.nodeType === 1 && node.matches(selector)) {
44
+ node.removeEventListener('input', configureCssBlankAttribute);
45
+ }
46
+ });
47
+ }
48
+ });
49
+ }).observe(document, {
50
+ childList: true,
51
+ subtree: true
52
+ }); // update a form control element’s css-blank attribute
53
+
54
+ function configureCssBlankAttribute() {
55
+ if (this.value) {
56
+ if (attr) {
57
+ this.removeAttribute(attr);
58
+ }
59
+
60
+ if (className) {
61
+ this.classList.remove(className);
62
+ }
63
+
64
+ this.removeAttribute('blank');
65
+ } else {
66
+ if (attr) {
67
+ this.setAttribute('blank', attr);
68
+ }
69
+
70
+ if (className) {
71
+ this.classList.add(className);
72
+ }
73
+ }
74
+ } // observe changes to the "value" property on an HTML Element
75
+
76
+
77
+ function observeValueOfHTMLElement(HTMLElement) {
78
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
79
+ const nativeSet = descriptor.set;
80
+
81
+ descriptor.set = function set(value) {
82
+ // eslint-disable-line no-unused-vars
83
+ nativeSet.apply(this, arguments);
84
+ configureCssBlankAttribute.apply(this);
85
+ };
86
+
87
+ Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
88
+ }
89
+ }
90
+
91
+ export { cssBlankPseudo as default };
92
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["src/browser.js"],"sourcesContent":["export 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\n\t// form control elements selector\n\tconst selector = '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\tnode.addEventListener('input', configureCssBlankAttribute);\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\tif (mutation.addedNodes) {\n\t\t\t\tmutation.addedNodes.forEach(\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && node.matches(selector)) {\n\t\t\t\t\t\t\tnode.addEventListener('input', configureCssBlankAttribute);\n\t\t\t\t\t\t\tconfigureCssBlankAttribute.call(node);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (mutation.removedNodes) {\n\t\t\t\tmutation.removedNodes.forEach(\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && node.matches(selector)) {\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) {\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"],"names":["cssBlankPseudo","document","opts","className","Object","attr","force","querySelector","ignoredError","window","ownerDocument","defaultView","observeValueOfHTMLElement","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","selector","Array","prototype","forEach","call","querySelectorAll","node","addEventListener","configureCssBlankAttribute","MutationObserver","mutationsList","mutation","addedNodes","nodeType","matches","removedNodes","removeEventListener","observe","childList","subtree","value","removeAttribute","classList","remove","setAttribute","add","HTMLElement","descriptor","getOwnPropertyDescriptor","nativeSet","set","apply","arguments","defineProperty"],"mappings":"AAAe,SAASA,cAAT,CAAyBC,QAAzB,EAAmCC,IAAnC,EAAyC;AACvD;AACA,QAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;AACA,QAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;AACA,QAAMC,KAAK,GAAG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,CAAiC,IAAjC;AACA,KAJD;;AAMA3C,IAAAA,MAAM,CAAC6C,cAAP,CAAsBP,WAAW,CAACxB,SAAlC,EAA6C,OAA7C,EAAsDyB,UAAtD;AACA;AACD;;;;"}
package/legacy.js ADDED
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ function cssBlankPseudo(document, opts) {
4
+ // configuration
5
+ const className = Object(opts).className;
6
+ const attr = Object(opts).attr || 'blank';
7
+ const force = Object(opts).force;
8
+
9
+ try {
10
+ document.querySelector(':blank');
11
+
12
+ if (!force) {
13
+ return;
14
+ }
15
+ } catch (ignoredError) {
16
+ /* do nothing and continue */
17
+ } // observe value changes on <input>, <select>, and <textarea>
18
+
19
+
20
+ const window = (document.ownerDocument || document).defaultView;
21
+ observeValueOfHTMLElement(window.HTMLInputElement);
22
+ observeValueOfHTMLElement(window.HTMLSelectElement);
23
+ observeValueOfHTMLElement(window.HTMLTextAreaElement);
24
+ observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
25
+
26
+ const selector = 'INPUT,SELECT,TEXTAREA';
27
+ const selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
28
+
29
+ Array.prototype.forEach.call(document.querySelectorAll(selector), node => {
30
+ if (node.nodeName === 'SELECT') {
31
+ node.addEventListener('change', configureCssBlankAttribute);
32
+ } else {
33
+ node.addEventListener('input', configureCssBlankAttribute);
34
+ }
35
+
36
+ configureCssBlankAttribute.call(node);
37
+ }); // conditionally observe added or unobserve removed form control elements
38
+
39
+ new MutationObserver(mutationsList => {
40
+ mutationsList.forEach(mutation => {
41
+ Array.prototype.forEach.call(mutation.addedNodes || [], node => {
42
+ if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
43
+ if (node.nodeName === 'SELECT') {
44
+ node.addEventListener('change', configureCssBlankAttribute);
45
+ } else {
46
+ node.addEventListener('input', configureCssBlankAttribute);
47
+ }
48
+
49
+ configureCssBlankAttribute.call(node);
50
+ }
51
+ });
52
+ Array.prototype.forEach.call(mutation.removedNodes || [], node => {
53
+ if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
54
+ if (node.nodeName === 'SELECT') {
55
+ node.removeEventListener('change', configureCssBlankAttribute);
56
+ } else {
57
+ node.removeEventListener('input', configureCssBlankAttribute);
58
+ }
59
+ }
60
+ });
61
+ });
62
+ }).observe(document, {
63
+ childList: true,
64
+ subtree: true
65
+ }); // update a form control element’s css-blank attribute
66
+
67
+ function configureCssBlankAttribute() {
68
+ if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) {
69
+ if (attr) {
70
+ this.removeAttribute(attr);
71
+ }
72
+
73
+ if (className) {
74
+ this.classList.remove(className);
75
+ }
76
+
77
+ this.removeAttribute('blank');
78
+ } else {
79
+ if (attr) {
80
+ this.setAttribute('blank', attr);
81
+ }
82
+
83
+ if (className) {
84
+ this.classList.add(className);
85
+ }
86
+ }
87
+ } // observe changes to the "value" property on an HTML Element
88
+
89
+
90
+ function observeValueOfHTMLElement(HTMLElement) {
91
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
92
+ const nativeSet = descriptor.set;
93
+
94
+ descriptor.set = function set(value) {
95
+ // eslint-disable-line no-unused-vars
96
+ nativeSet.apply(this, arguments);
97
+ configureCssBlankAttribute.apply(this);
98
+ };
99
+
100
+ Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
101
+ } // observe changes to the "selected" property on an HTML Element
102
+
103
+
104
+ function observeSelectedOfHTMLElement(HTMLElement) {
105
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
106
+ const nativeSet = descriptor.set;
107
+
108
+ descriptor.set = function set(value) {
109
+ // eslint-disable-line no-unused-vars
110
+ nativeSet.apply(this, arguments);
111
+ const event = document.createEvent('Event');
112
+ event.initEvent('change', true, true);
113
+ this.dispatchEvent(event);
114
+ };
115
+
116
+ Object.defineProperty(HTMLElement.prototype, 'selected', descriptor);
117
+ }
118
+ }
119
+
120
+ module.exports = cssBlankPseudo;
121
+ //# sourceMappingURL=legacy.js.map
package/legacy.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.js","sources":["src/browser-legacy.js"],"sourcesContent":["export 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"],"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"],"mappings":";;AAAe,SAASA,cAAT,CAAyBC,QAAzB,EAAmCC,IAAnC,EAAyC;AACvD;AACA,QAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;AACA,QAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;AACA,QAAMC,KAAK,GAAGF,MAAM,CAACF,IAAD,CAAN,CAAaI,KAA3B;;AAEA,MAAI;AACHL,IAAAA,QAAQ,CAACM,aAAT,CAAuB,QAAvB;;AAEA,QAAI,CAACD,KAAL,EAAY;AACX;AACA;AACD,GAND,CAME,OAAOE,YAAP,EAAqB;AAAE;AAA+B,GAZD;;;AAevD,QAAMC,MAAM,GAAG,CAACR,QAAQ,CAACS,aAAT,IAA0BT,QAA3B,EAAq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 const className = Object(opts).className;
4
+ const attr = Object(opts).attr || 'blank';
5
+ const force = Object(opts).force;
6
+
7
+ try {
8
+ document.querySelector(':blank');
9
+
10
+ if (!force) {
11
+ return;
12
+ }
13
+ } catch (ignoredError) {
14
+ /* do nothing and continue */
15
+ } // observe value changes on <input>, <select>, and <textarea>
16
+
17
+
18
+ const window = (document.ownerDocument || document).defaultView;
19
+ observeValueOfHTMLElement(window.HTMLInputElement);
20
+ observeValueOfHTMLElement(window.HTMLSelectElement);
21
+ observeValueOfHTMLElement(window.HTMLTextAreaElement);
22
+ observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
23
+
24
+ const selector = 'INPUT,SELECT,TEXTAREA';
25
+ const selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
26
+
27
+ Array.prototype.forEach.call(document.querySelectorAll(selector), node => {
28
+ if (node.nodeName === 'SELECT') {
29
+ node.addEventListener('change', configureCssBlankAttribute);
30
+ } else {
31
+ node.addEventListener('input', configureCssBlankAttribute);
32
+ }
33
+
34
+ configureCssBlankAttribute.call(node);
35
+ }); // conditionally observe added or unobserve removed form control elements
36
+
37
+ new MutationObserver(mutationsList => {
38
+ mutationsList.forEach(mutation => {
39
+ Array.prototype.forEach.call(mutation.addedNodes || [], node => {
40
+ if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
41
+ if (node.nodeName === 'SELECT') {
42
+ node.addEventListener('change', configureCssBlankAttribute);
43
+ } else {
44
+ node.addEventListener('input', configureCssBlankAttribute);
45
+ }
46
+
47
+ configureCssBlankAttribute.call(node);
48
+ }
49
+ });
50
+ Array.prototype.forEach.call(mutation.removedNodes || [], node => {
51
+ if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
52
+ if (node.nodeName === 'SELECT') {
53
+ node.removeEventListener('change', configureCssBlankAttribute);
54
+ } else {
55
+ node.removeEventListener('input', configureCssBlankAttribute);
56
+ }
57
+ }
58
+ });
59
+ });
60
+ }).observe(document, {
61
+ childList: true,
62
+ subtree: true
63
+ }); // update a form control element’s css-blank attribute
64
+
65
+ function configureCssBlankAttribute() {
66
+ if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) {
67
+ if (attr) {
68
+ this.removeAttribute(attr);
69
+ }
70
+
71
+ if (className) {
72
+ this.classList.remove(className);
73
+ }
74
+
75
+ this.removeAttribute('blank');
76
+ } else {
77
+ if (attr) {
78
+ this.setAttribute('blank', attr);
79
+ }
80
+
81
+ if (className) {
82
+ this.classList.add(className);
83
+ }
84
+ }
85
+ } // observe changes to the "value" property on an HTML Element
86
+
87
+
88
+ function observeValueOfHTMLElement(HTMLElement) {
89
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
90
+ const nativeSet = descriptor.set;
91
+
92
+ descriptor.set = function set(value) {
93
+ // eslint-disable-line no-unused-vars
94
+ nativeSet.apply(this, arguments);
95
+ configureCssBlankAttribute.apply(this);
96
+ };
97
+
98
+ Object.defineProperty(HTMLElement.prototype, 'value', descriptor);
99
+ } // observe changes to the "selected" property on an HTML Element
100
+
101
+
102
+ function observeSelectedOfHTMLElement(HTMLElement) {
103
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
104
+ const nativeSet = descriptor.set;
105
+
106
+ descriptor.set = function set(value) {
107
+ // eslint-disable-line no-unused-vars
108
+ nativeSet.apply(this, arguments);
109
+ const event = document.createEvent('Event');
110
+ event.initEvent('change', true, true);
111
+ this.dispatchEvent(event);
112
+ };
113
+
114
+ Object.defineProperty(HTMLElement.prototype, 'selected', descriptor);
115
+ }
116
+ }
117
+
118
+ export { cssBlankPseudo as default };
119
+ //# sourceMappingURL=legacy.mjs.map
package/legacy.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.mjs","sources":["src/browser-legacy.js"],"sourcesContent":["export 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"],"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"],"mappings":"AAAe,SAASA,cAAT,CAAyBC,QAAzB,EAAmCC,IAAnC,EAAyC;AACvD;AACA,QAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;AACA,QAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;AACA,QAAMC,KAAK,GAAGF,MAAM,CAACF,IAAD,CAAN,CAAaI,KAA3B;;AAEA,MAAI;AACHL,IAAAA,QAAQ,CAACM,aAAT,CAAuB,QAAvB;;AAEA,QAAI,CAACD,KAAL,EAAY;AACX;AACA;AACD,GAND,CAME,OAAOE,YAAP,EAAqB;AAAE;AAA+B,GAZD;;;AAevD,QAAMC,MAAM,GAAG,CAACR,QAAQ,CAACS,aAAT,IAA0BT,QAA3B,EAAqCU,WAApD;AAEAC,EAAAA,yBAAyB,CAACH,MAAM,CAACI,gBAAR,CAAzB;AACAD,EAAAA,yBAAyB,CAACH,MAAM,CAACK,iBAAR,CAAzB;AACAF,EAAAA,yBAAyB,CAACH,MAAM,CAACM,mBAAR,CAAzB;AACAC,EAAAA,4BAA4B,CAACP,MAAM,CAACQ,iBAAR,CAA5B,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GAAX,GAAiB,SAASA,GAAT,CAAcZ,KAAd,EAAqB;AAAE;AACvCW,MAAAA,SAAS,CAACE,KAAV,CAAgB,IAAhB,EAAsBC,SAAtB;AAEA1B,MAAAA,0BAA0B,CAACyB,KAA3B,CAAiC,IAAjC;AACA,KAJD;;AAMAjD,IAAAA,MAAM,CAACmD,cAAP,CAAsBP,WAAW,CAAC3B,SAAlC,EAA6C,OAA7C,EAAsD4B,UAAtD;AACA,GA3GsD;;;AA8GvD,WAASjC,4BAAT,CAAuCgC,WAAvC,EAAoD;AACnD,UAAMC,UAAU,GAAG7C,MAAM,CAAC8C,wBAAP,CAAgCF,WAAW,CAAC3B,SAA5C,EAAuD,UAAvD,CAAnB;AACA,UAAM8B,SAAS,GAAGF,UAAU,CAACG,GAA7B;;AAEAH,IAAAA,UAAU,CAACG,GAAX,GAAiB,SAASA,GAAT,CAAcZ,KAAd,EAAqB;AAAE;AACvCW,MAAAA,SAAS,CAACE,KAAV,CAAgB,IAAhB,EAAsBC,SAAtB;AAEA,YAAME,KAAK,GAAGvD,QAAQ,CAACwD,WAAT,CAAqB,OAArB,CAAd;AACAD,MAAAA,KAAK,CAACE,SAAN,CAAgB,QAAhB,EAA0B,IAA1B,EAAgC,IAAhC;AACA,WAAKC,aAAL,CAAmBH,KAAnB;AACA,KAND;;AAQApD,IAAAA,MAAM,CAACmD,cAAP,CAAsBP,WAAW,CAAC3B,SAAlC,EAA6C,UAA7C,EAAyD4B,UAAzD;AACA;AACD;;;;"}
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "css-blank-pseudo",
3
+ "version": "2.0.0",
4
+ "description": "Style form elements when they are empty",
5
+ "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
+ "license": "CC0-1.0",
7
+ "repository": "csstools/css-blank-pseudo",
8
+ "homepage": "https://github.com/csstools/css-blank-pseudo#readme",
9
+ "bugs": "https://github.com/csstools/css-blank-pseudo/issues",
10
+ "main": "index.js",
11
+ "module": "index.mjs",
12
+ "bin": {
13
+ "css-blank-pseudo": "cli.js"
14
+ },
15
+ "files": [
16
+ "browser.js",
17
+ "browser-legacy.js",
18
+ "cli.js",
19
+ "index.js",
20
+ "index.js.map",
21
+ "index.mjs",
22
+ "index.mjs.map",
23
+ "legacy.js",
24
+ "legacy.js.map",
25
+ "legacy.mjs",
26
+ "legacy.mjs.map",
27
+ "postcss.js",
28
+ "postcss.js.map",
29
+ "postcss.mjs",
30
+ "postcss.mjs.map"
31
+ ],
32
+ "scripts": {
33
+ "build": "npm run build:browser && npm run build:cli && npm run build:node && npm run build:postcss",
34
+ "build:browser": "cross-env NODE_ENV=browser rollup --config .rollup.js --silent && cross-env NODE_ENV=browser:legacy rollup --config .rollup.js --silent",
35
+ "build:cli": "cross-env NODE_ENV=cli rollup --config .rollup.js --silent",
36
+ "build:postcss": "cross-env NODE_ENV=postcss rollup --config .rollup.js --silent",
37
+ "build:node": "rollup --config .rollup.js --silent && cross-env NODE_ENV=legacy rollup --config .rollup.js --silent",
38
+ "prepublishOnly": "npm test && npm run build",
39
+ "pretest:postcss": "npm run build:postcss",
40
+ "test": "npm run test:js && npm run test:postcss",
41
+ "test:js": "eslint src/{*,**/*}.js --cache --ignore-path .gitignore --quiet",
42
+ "test:postcss": "postcss-tape --plugin postcss.js"
43
+ },
44
+ "engines": {
45
+ "node": ">=10.0.0"
46
+ },
47
+ "peerDependencies": {
48
+ "postcss": "^8.3"
49
+ },
50
+ "devDependencies": {
51
+ "@babel/core": "^7.15.5",
52
+ "@babel/preset-env": "^7.15.6",
53
+ "@rollup/plugin-babel": "^5.3.0",
54
+ "cross-env": "^7.0.3",
55
+ "eslint": "^7.32.0",
56
+ "postcss": "^8.3.6",
57
+ "postcss-tape": "^6.0.1",
58
+ "pre-commit": "^1.2.2",
59
+ "rollup": "^2.56.3",
60
+ "rollup-plugin-terser": "^7.0.2"
61
+ },
62
+ "eslintConfig": {
63
+ "env": {
64
+ "browser": true,
65
+ "es6": true,
66
+ "node": true
67
+ },
68
+ "parserOptions": {
69
+ "sourceType": "module"
70
+ },
71
+ "root": true
72
+ },
73
+ "keywords": [
74
+ "postcss",
75
+ "css",
76
+ "postcss-plugin",
77
+ "javascript",
78
+ "js",
79
+ "polyfill",
80
+ "blank",
81
+ "empty",
82
+ "pseudo",
83
+ "selectors",
84
+ "accessibility",
85
+ "a11y",
86
+ "input",
87
+ "select",
88
+ "textarea"
89
+ ]
90
+ }
package/postcss.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const selectorRegExp = /:blank([^\w-]|$)/gi;
4
+
5
+ const creator = opts => {
6
+ const replaceWith = String(Object(opts).replaceWith || '[blank]');
7
+ const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
8
+ return {
9
+ postcssPlugin: 'css-blank-pseudo',
10
+ Once: root => {
11
+ root.walkRules(selectorRegExp, rule => {
12
+ const selector = rule.selector.replace(selectorRegExp, ($0, $1) => {
13
+ return `${replaceWith}${$1}`;
14
+ });
15
+ const clone = rule.clone({
16
+ selector
17
+ });
18
+
19
+ if (preserve) {
20
+ rule.before(clone);
21
+ } else {
22
+ rule.replaceWith(clone);
23
+ }
24
+ });
25
+ }
26
+ };
27
+ };
28
+
29
+ creator.postcss = true;
30
+
31
+ module.exports = creator;
32
+ //# sourceMappingURL=postcss.js.map
package/postcss.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcss.js","sources":["src/postcss.js"],"sourcesContent":["const selectorRegExp = /:blank([^\\w-]|$)/gi;\n\nconst creator = opts => {\n\tconst replaceWith = String(Object(opts).replaceWith || '[blank]');\n\tconst preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);\n\n\treturn {\n\t\tpostcssPlugin: 'css-blank-pseudo',\n\t\tOnce: root => {\n\t\t\troot.walkRules(selectorRegExp, rule => {\n\t\t\t\tconst selector = rule.selector.replace(selectorRegExp, ($0, $1) => {\n\t\t\t\t\treturn `${replaceWith}${$1}`;\n\t\t\t\t});\n\n\t\t\t\tconst clone = rule.clone({ selector });\n\n\t\t\t\tif (preserve) {\n\t\t\t\t\trule.before(clone);\n\t\t\t\t} else {\n\t\t\t\t\trule.replaceWith(clone);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n};\n\ncreator.postcss = true\n\nexport default creator\n"],"names":["selectorRegExp","creator","opts","replaceWith","String","Object","preserve","Boolean","postcssPlugin","Once","root","walkRules","rule","selector","replace","$0","$1","clone","before","postcss"],"mappings":";;AAAA,MAAMA,cAAc,GAAG,oBAAvB;;MAEMC,OAAO,GAAGC,IAAI,IAAI;AACvB,QAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACH,IAAD,CAAN,CAAaC,WAAb,IAA4B,SAA7B,CAA1B;AACA,QAAMG,QAAQ,GAAGC,OAAO,CAAC,cAAcF,MAAM,CAACH,IAAD,CAApB,GAA6BA,IAAI,CAACI,QAAlC,GAA6C,IAA9C,CAAxB;AAEA,SAAO;AACNE,IAAAA,aAAa,EAAE,kBADT;AAENC,IAAAA,IAAI,EAAEC,IAAI,IAAI;AACbA,MAAAA,IAAI,CAACC,SAAL,CAAeX,cAAf,EAA+BY,IAAI,IAAI;AACtC,cAAMC,QAAQ,GAAGD,IAAI,CAACC,QAAL,CAAcC,OAAd,CAAsBd,cAAtB,EAAsC,CAACe,EAAD,EAAKC,EAAL,KAAY;AAClE,iBAAQ,GAAEb,WAAY,GAAEa,EAAG,EAA3B;AACA,SAFgB,CAAjB;AAIA,cAAMC,KAAK,GAAGL,IAAI,CAACK,KAAL,CAAW;AAAEJ,UAAAA;AAAF,SAAX,CAAd;;AAEA,YAAIP,QAAJ,EAAc;AACbM,UAAAA,IAAI,CAACM,MAAL,CAAYD,KAAZ;AACA,SAFD,MAEO;AACNL,UAAAA,IAAI,CAACT,WAAL,CAAiBc,KAAjB;AACA;AACD,OAZD;AAaA;AAhBK,GAAP;AAkBA;;AAEDhB,OAAO,CAACkB,OAAR,GAAkB,IAAlB;;;;"}
package/postcss.mjs ADDED
@@ -0,0 +1,30 @@
1
+ const selectorRegExp = /:blank([^\w-]|$)/gi;
2
+
3
+ const creator = opts => {
4
+ const replaceWith = String(Object(opts).replaceWith || '[blank]');
5
+ const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
6
+ return {
7
+ postcssPlugin: 'css-blank-pseudo',
8
+ Once: root => {
9
+ root.walkRules(selectorRegExp, rule => {
10
+ const selector = rule.selector.replace(selectorRegExp, ($0, $1) => {
11
+ return `${replaceWith}${$1}`;
12
+ });
13
+ const clone = rule.clone({
14
+ selector
15
+ });
16
+
17
+ if (preserve) {
18
+ rule.before(clone);
19
+ } else {
20
+ rule.replaceWith(clone);
21
+ }
22
+ });
23
+ }
24
+ };
25
+ };
26
+
27
+ creator.postcss = true;
28
+
29
+ export { creator as default };
30
+ //# sourceMappingURL=postcss.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcss.mjs","sources":["src/postcss.js"],"sourcesContent":["const selectorRegExp = /:blank([^\\w-]|$)/gi;\n\nconst creator = opts => {\n\tconst replaceWith = String(Object(opts).replaceWith || '[blank]');\n\tconst preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);\n\n\treturn {\n\t\tpostcssPlugin: 'css-blank-pseudo',\n\t\tOnce: root => {\n\t\t\troot.walkRules(selectorRegExp, rule => {\n\t\t\t\tconst selector = rule.selector.replace(selectorRegExp, ($0, $1) => {\n\t\t\t\t\treturn `${replaceWith}${$1}`;\n\t\t\t\t});\n\n\t\t\t\tconst clone = rule.clone({ selector });\n\n\t\t\t\tif (preserve) {\n\t\t\t\t\trule.before(clone);\n\t\t\t\t} else {\n\t\t\t\t\trule.replaceWith(clone);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n};\n\ncreator.postcss = true\n\nexport default creator\n"],"names":["selectorRegExp","creator","opts","replaceWith","String","Object","preserve","Boolean","postcssPlugin","Once","root","walkRules","rule","selector","replace","$0","$1","clone","before","postcss"],"mappings":"AAAA,MAAMA,cAAc,GAAG,oBAAvB;;MAEMC,OAAO,GAAGC,IAAI,IAAI;AACvB,QAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACH,IAAD,CAAN,CAAaC,WAAb,IAA4B,SAA7B,CAA1B;AACA,QAAMG,QAAQ,GAAGC,OAAO,CAAC,cAAcF,MAAM,CAACH,IAAD,CAApB,GAA6BA,IAAI,CAACI,QAAlC,GAA6C,IAA9C,CAAxB;AAEA,SAAO;AACNE,IAAAA,aAAa,EAAE,kBADT;AAENC,IAAAA,IAAI,EAAEC,IAAI,IAAI;AACbA,MAAAA,IAAI,CAACC,SAAL,CAAeX,cAAf,EAA+BY,IAAI,IAAI;AACtC,cAAMC,QAAQ,GAAGD,IAAI,CAACC,QAAL,CAAcC,OAAd,CAAsBd,cAAtB,EAAsC,CAACe,EAAD,EAAKC,EAAL,KAAY;AAClE,iBAAQ,GAAEb,WAAY,GAAEa,EAAG,EAA3B;AACA,SAFgB,CAAjB;AAIA,cAAMC,KAAK,GAAGL,IAAI,CAACK,KAAL,CAAW;AAAEJ,UAAAA;AAAF,SAAX,CAAd;;AAEA,YAAIP,QAAJ,EAAc;AACbM,UAAAA,IAAI,CAACM,MAAL,CAAYD,KAAZ;AACA,SAFD,MAEO;AACNL,UAAAA,IAAI,CAACT,WAAL,CAAiBc,KAAjB;AACA;AACD,OAZD;AAaA;AAhBK,GAAP;AAkBA;;AAEDhB,OAAO,CAACkB,OAAR,GAAkB,IAAlB;;;;"}