css-blank-pseudo 1.0.0 → 3.0.2
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 +62 -0
- package/README.md +34 -16
- package/browser.js +125 -2
- package/dist/browser-global.js +125 -0
- package/dist/browser-global.js.map +1 -0
- package/{legacy.js → dist/browser.cjs} +21 -22
- package/dist/browser.cjs.map +1 -0
- package/{legacy.mjs → dist/browser.mjs} +22 -21
- package/dist/browser.mjs.map +1 -0
- package/dist/cli.cjs +3 -0
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +51 -65
- package/browser-legacy.js +0 -2
- package/cli.js +0 -129
- package/index.js +0 -94
- package/index.js.map +0 -1
- package/index.mjs +0 -92
- package/index.mjs.map +0 -1
- package/legacy.js.map +0 -1
- package/legacy.mjs.map +0 -1
- package/postcss.js +0 -30
- package/postcss.js.map +0 -1
- package/postcss.mjs +0 -26
- package/postcss.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# Changes to CSS Blank Pseudo
|
|
2
2
|
|
|
3
|
+
### 3.0.2 (January 2, 2022)
|
|
4
|
+
|
|
5
|
+
- Removed Sourcemaps from package tarball.
|
|
6
|
+
- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
|
|
7
|
+
|
|
8
|
+
### 3.0.1 (December 27, 2021)
|
|
9
|
+
|
|
10
|
+
- Fixed: require/import paths for browser script
|
|
11
|
+
|
|
12
|
+
### 3.0.0 (December 13, 2021)
|
|
13
|
+
|
|
14
|
+
- Breaking: require/import paths have changed
|
|
15
|
+
- Changed: new polyfill CDN urls.
|
|
16
|
+
- Changed: Supports Node 12+ (major).
|
|
17
|
+
- Updated: documentation
|
|
18
|
+
|
|
19
|
+
**Migrating to 3.0.0**
|
|
20
|
+
|
|
21
|
+
PostCSS plugin :
|
|
22
|
+
|
|
23
|
+
```diff
|
|
24
|
+
- const postcssBlankPseudo = require('css-blank-pseudo/postcss');
|
|
25
|
+
+ const postcssBlankPseudo = require('css-blank-pseudo');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Browser Polyfill :
|
|
29
|
+
|
|
30
|
+
```diff
|
|
31
|
+
- const cssBlankPseudo = require('css-blank-pseudo');
|
|
32
|
+
+ const cssBlankPseudo = require('css-blank-pseudo/browser');
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
_The old CND url is now deprecated and will be removed in a next major release._
|
|
36
|
+
_It will continue to work for now._
|
|
37
|
+
|
|
38
|
+
```diff
|
|
39
|
+
- <script src="https://unpkg.com/css-blank-pseudo/browser"></script>
|
|
40
|
+
+ <script src="https://unpkg.com/css-blank-pseudo/dist/browser-global.js"></script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Browser Polyfill IE :
|
|
44
|
+
|
|
45
|
+
_The polyfill for IE is now the same as the general polyfill_
|
|
46
|
+
|
|
47
|
+
```diff
|
|
48
|
+
- const cssBlankPseudo = require('css-blank-pseudo');
|
|
49
|
+
+ const cssBlankPseudo = require('css-blank-pseudo/browser');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
_The old CND url is now deprecated and will be removed in a next major release._
|
|
53
|
+
_It will continue to work for now._
|
|
54
|
+
|
|
55
|
+
```diff
|
|
56
|
+
- <script src="https://unpkg.com/css-blank-pseudo/browser-legacy"></script>
|
|
57
|
+
+ <script src="https://unpkg.com/css-blank-pseudo/dist/browser-global.js"></script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2.0.0 (September 16, 2021)
|
|
61
|
+
|
|
62
|
+
- Changed: Supports PostCSS 8.3+ (major).
|
|
63
|
+
- Changed: Supports Node 10+ (major).
|
|
64
|
+
|
|
3
65
|
### 1.0.0 (June 10, 2019)
|
|
4
66
|
|
|
5
67
|
- Updated: `postcss` to 7.0.16 (patch)
|
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# CSS Blank Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Blank Pseudo]
|
|
2
2
|
|
|
3
3
|
[![NPM Version][npm-img]][npm-url]
|
|
4
|
-
[![Build Status][cli-img]][cli-url]
|
|
5
4
|
[![Support Chat][git-img]][git-url]
|
|
6
5
|
|
|
7
6
|
[CSS Blank Pseudo] lets you style form elements when they are empty, following
|
|
@@ -22,29 +21,24 @@ input:blank {
|
|
|
22
21
|
From the command line, transform CSS files that use `:blank` selectors:
|
|
23
22
|
|
|
24
23
|
```bash
|
|
25
|
-
npx css-blank-pseudo SOURCE.css TRANSFORMED.css
|
|
24
|
+
npx css-blank-pseudo SOURCE.css --output TRANSFORMED.css
|
|
26
25
|
```
|
|
27
26
|
|
|
28
27
|
Next, use your transformed CSS with this script:
|
|
29
28
|
|
|
30
29
|
```html
|
|
31
30
|
<link rel="stylesheet" href="TRANSFORMED.css">
|
|
32
|
-
<script src="https://unpkg.com/css-blank-pseudo/browser"></script>
|
|
31
|
+
<script src="https://unpkg.com/css-blank-pseudo/dist/browser-global.js"></script>
|
|
33
32
|
<script>cssBlankPseudo(document)</script>
|
|
34
33
|
```
|
|
35
34
|
|
|
36
|
-
|
|
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.
|
|
37
37
|
|
|
38
|
-
|
|
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.
|
|
39
40
|
|
|
40
|
-
|
|
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
|
-
```
|
|
41
|
+
That’s it. The script works in most browsers.
|
|
48
42
|
|
|
49
43
|
## How it works
|
|
50
44
|
|
|
@@ -75,13 +69,37 @@ elements otherwise matching `:blank` natively.
|
|
|
75
69
|
<input value="This element has a value">
|
|
76
70
|
```
|
|
77
71
|
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
## ⚠️ `:not(:blank)`
|
|
73
|
+
|
|
74
|
+
with option : `preserve` `true`
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
input:not(:blank) {
|
|
78
|
+
background-color: yellow;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* becomes */
|
|
82
|
+
|
|
83
|
+
input:not([blank]) {
|
|
84
|
+
background-color: yellow;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
input:not(:blank) {
|
|
88
|
+
background-color: yellow;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
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.
|
|
94
|
+
|
|
95
|
+
_currently no browsers support `:blank`_
|
|
96
|
+
|
|
97
|
+
|
|
80
98
|
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
|
81
99
|
[git-url]: https://gitter.im/postcss/postcss
|
|
82
100
|
[npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg
|
|
83
101
|
[npm-url]: https://www.npmjs.com/package/css-blank-pseudo
|
|
84
102
|
|
|
85
|
-
[CSS Blank Pseudo]: https://github.com/csstools/css-blank-pseudo
|
|
103
|
+
[CSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
|
|
86
104
|
[PostCSS Preset Env]: https://preset-env.cssdb.org/
|
|
87
105
|
[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#blank
|
package/browser.js
CHANGED
|
@@ -1,2 +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
|
+
})();
|
|
125
|
+
//# sourceMappingURL=browser-global.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
})();
|
|
125
|
+
//# sourceMappingURL=browser-global.js.map
|
|
@@ -0,0 +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,C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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,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* global MutationObserver */
|
|
3
2
|
function cssBlankPseudo(document, opts) {
|
|
4
3
|
// configuration
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
var className = Object(opts).className;
|
|
5
|
+
var attr = Object(opts).attr || 'blank';
|
|
6
|
+
var force = Object(opts).force;
|
|
8
7
|
|
|
9
8
|
try {
|
|
10
9
|
document.querySelector(':blank');
|
|
@@ -12,21 +11,21 @@ function cssBlankPseudo(document, opts) {
|
|
|
12
11
|
if (!force) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
} catch (ignoredError) {
|
|
16
|
-
|
|
17
|
-
// observe value changes on <input>, <select>, and <textarea>
|
|
14
|
+
} catch (ignoredError) {
|
|
15
|
+
/* do nothing and continue */
|
|
16
|
+
} // observe value changes on <input>, <select>, and <textarea>
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
var window = (document.ownerDocument || document).defaultView;
|
|
21
20
|
observeValueOfHTMLElement(window.HTMLInputElement);
|
|
22
21
|
observeValueOfHTMLElement(window.HTMLSelectElement);
|
|
23
22
|
observeValueOfHTMLElement(window.HTMLTextAreaElement);
|
|
24
23
|
observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
var selector = 'INPUT,SELECT,TEXTAREA';
|
|
26
|
+
var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
|
|
28
27
|
|
|
29
|
-
Array.prototype.forEach.call(document.querySelectorAll(selector), node
|
|
28
|
+
Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) {
|
|
30
29
|
if (node.nodeName === 'SELECT') {
|
|
31
30
|
node.addEventListener('change', configureCssBlankAttribute);
|
|
32
31
|
} else {
|
|
@@ -36,9 +35,9 @@ function cssBlankPseudo(document, opts) {
|
|
|
36
35
|
configureCssBlankAttribute.call(node);
|
|
37
36
|
}); // conditionally observe added or unobserve removed form control elements
|
|
38
37
|
|
|
39
|
-
new MutationObserver(mutationsList
|
|
40
|
-
mutationsList.forEach(mutation
|
|
41
|
-
Array.prototype.forEach.call(mutation.addedNodes || [], node
|
|
38
|
+
new MutationObserver(function (mutationsList) {
|
|
39
|
+
mutationsList.forEach(function (mutation) {
|
|
40
|
+
Array.prototype.forEach.call(mutation.addedNodes || [], function (node) {
|
|
42
41
|
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
|
|
43
42
|
if (node.nodeName === 'SELECT') {
|
|
44
43
|
node.addEventListener('change', configureCssBlankAttribute);
|
|
@@ -49,7 +48,7 @@ function cssBlankPseudo(document, opts) {
|
|
|
49
48
|
configureCssBlankAttribute.call(node);
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
|
-
Array.prototype.forEach.call(mutation.removedNodes || [], node
|
|
51
|
+
Array.prototype.forEach.call(mutation.removedNodes || [], function (node) {
|
|
53
52
|
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
|
|
54
53
|
if (node.nodeName === 'SELECT') {
|
|
55
54
|
node.removeEventListener('change', configureCssBlankAttribute);
|
|
@@ -88,8 +87,8 @@ function cssBlankPseudo(document, opts) {
|
|
|
88
87
|
|
|
89
88
|
|
|
90
89
|
function observeValueOfHTMLElement(HTMLElement) {
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
|
|
91
|
+
var nativeSet = descriptor.set;
|
|
93
92
|
|
|
94
93
|
descriptor.set = function set(value) {
|
|
95
94
|
// eslint-disable-line no-unused-vars
|
|
@@ -102,13 +101,13 @@ function cssBlankPseudo(document, opts) {
|
|
|
102
101
|
|
|
103
102
|
|
|
104
103
|
function observeSelectedOfHTMLElement(HTMLElement) {
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
|
|
105
|
+
var nativeSet = descriptor.set;
|
|
107
106
|
|
|
108
107
|
descriptor.set = function set(value) {
|
|
109
108
|
// eslint-disable-line no-unused-vars
|
|
110
109
|
nativeSet.apply(this, arguments);
|
|
111
|
-
|
|
110
|
+
var event = document.createEvent('Event');
|
|
112
111
|
event.initEvent('change', true, true);
|
|
113
112
|
this.dispatchEvent(event);
|
|
114
113
|
};
|
|
@@ -118,4 +117,4 @@ function cssBlankPseudo(document, opts) {
|
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
module.exports = cssBlankPseudo;
|
|
121
|
-
//# sourceMappingURL=
|
|
120
|
+
//# sourceMappingURL=browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.cjs","sources":["../src/browser.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"],"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":"AAAA;AACe,SAASA,cAAT,CAAwBC,QAAxB,EAAkCC,IAAlC,EAAwC;AACtD;AACA,MAAMC,SAAS,GAAGC,MAAM,CAACF,IAAD,CAAN,CAAaC,SAA/B;AACA,MAAME,IAAI,GAAGD,MAAM,CAACF,IAAD,CAAN,CAAaG,IAAb,IAAqB,OAAlC;AACA,MAAMC,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,GAZF;;;AAetD,MAAMC,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,CApBsD;;AAuBtD,MAAMC,QAAQ,GAAG,uBAAjB;AACA,MAAMC,cAAc,GAAG,2BAAvB,CAxBsD;;AA2BtDC,EAAAA,KAAK,CAACC,SAAN,CAAgBC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hB,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,GA3GqD;;;AA8GtD,WAASjC,4BAAT,CAAuCgC,WAAvC,EAAoD;AACnD,QAAMC,UAAU,GAAG7C,MAAM,CAAC8C,wBAAP,CAAgCF,WAAW,CAAC3B,SAA5C,EAAuD,UAAvD,CAAnB;AACA,QAAM8B,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,UAAME,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;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* global MutationObserver */
|
|
1
2
|
function cssBlankPseudo(document, opts) {
|
|
2
3
|
// configuration
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var className = Object(opts).className;
|
|
5
|
+
var attr = Object(opts).attr || 'blank';
|
|
6
|
+
var force = Object(opts).force;
|
|
6
7
|
|
|
7
8
|
try {
|
|
8
9
|
document.querySelector(':blank');
|
|
@@ -10,21 +11,21 @@ function cssBlankPseudo(document, opts) {
|
|
|
10
11
|
if (!force) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
|
-
} catch (ignoredError) {
|
|
14
|
-
|
|
15
|
-
// observe value changes on <input>, <select>, and <textarea>
|
|
14
|
+
} catch (ignoredError) {
|
|
15
|
+
/* do nothing and continue */
|
|
16
|
+
} // observe value changes on <input>, <select>, and <textarea>
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
var window = (document.ownerDocument || document).defaultView;
|
|
19
20
|
observeValueOfHTMLElement(window.HTMLInputElement);
|
|
20
21
|
observeValueOfHTMLElement(window.HTMLSelectElement);
|
|
21
22
|
observeValueOfHTMLElement(window.HTMLTextAreaElement);
|
|
22
23
|
observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
var selector = 'INPUT,SELECT,TEXTAREA';
|
|
26
|
+
var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements
|
|
26
27
|
|
|
27
|
-
Array.prototype.forEach.call(document.querySelectorAll(selector), node
|
|
28
|
+
Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) {
|
|
28
29
|
if (node.nodeName === 'SELECT') {
|
|
29
30
|
node.addEventListener('change', configureCssBlankAttribute);
|
|
30
31
|
} else {
|
|
@@ -34,9 +35,9 @@ function cssBlankPseudo(document, opts) {
|
|
|
34
35
|
configureCssBlankAttribute.call(node);
|
|
35
36
|
}); // conditionally observe added or unobserve removed form control elements
|
|
36
37
|
|
|
37
|
-
new MutationObserver(mutationsList
|
|
38
|
-
mutationsList.forEach(mutation
|
|
39
|
-
Array.prototype.forEach.call(mutation.addedNodes || [], node
|
|
38
|
+
new MutationObserver(function (mutationsList) {
|
|
39
|
+
mutationsList.forEach(function (mutation) {
|
|
40
|
+
Array.prototype.forEach.call(mutation.addedNodes || [], function (node) {
|
|
40
41
|
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
|
|
41
42
|
if (node.nodeName === 'SELECT') {
|
|
42
43
|
node.addEventListener('change', configureCssBlankAttribute);
|
|
@@ -47,7 +48,7 @@ function cssBlankPseudo(document, opts) {
|
|
|
47
48
|
configureCssBlankAttribute.call(node);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
|
-
Array.prototype.forEach.call(mutation.removedNodes || [], node
|
|
51
|
+
Array.prototype.forEach.call(mutation.removedNodes || [], function (node) {
|
|
51
52
|
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) {
|
|
52
53
|
if (node.nodeName === 'SELECT') {
|
|
53
54
|
node.removeEventListener('change', configureCssBlankAttribute);
|
|
@@ -86,8 +87,8 @@ function cssBlankPseudo(document, opts) {
|
|
|
86
87
|
|
|
87
88
|
|
|
88
89
|
function observeValueOfHTMLElement(HTMLElement) {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');
|
|
91
|
+
var nativeSet = descriptor.set;
|
|
91
92
|
|
|
92
93
|
descriptor.set = function set(value) {
|
|
93
94
|
// eslint-disable-line no-unused-vars
|
|
@@ -100,13 +101,13 @@ function cssBlankPseudo(document, opts) {
|
|
|
100
101
|
|
|
101
102
|
|
|
102
103
|
function observeSelectedOfHTMLElement(HTMLElement) {
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');
|
|
105
|
+
var nativeSet = descriptor.set;
|
|
105
106
|
|
|
106
107
|
descriptor.set = function set(value) {
|
|
107
108
|
// eslint-disable-line no-unused-vars
|
|
108
109
|
nativeSet.apply(this, arguments);
|
|
109
|
-
|
|
110
|
+
var event = document.createEvent('Event');
|
|
110
111
|
event.initEvent('change', true, true);
|
|
111
112
|
this.dispatchEvent(event);
|
|
112
113
|
};
|
|
@@ -115,5 +116,5 @@ function cssBlankPseudo(document, opts) {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
export default
|
|
119
|
-
//# sourceMappingURL=
|
|
119
|
+
export { cssBlankPseudo as default };
|
|
120
|
+
//# sourceMappingURL=browser.mjs.map
|