css-has-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 +44 -0
- package/README.md +14 -7
- package/browser.js +117 -2
- package/dist/browser-global.js +117 -0
- package/dist/browser-global.js.map +1 -0
- package/{index.js → dist/browser.cjs} +27 -24
- package/dist/browser.cjs.map +1 -0
- package/{index.mjs → dist/browser.mjs} +28 -23
- 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 +50 -56
- package/cli.js +0 -158
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/postcss.js +0 -48
- package/postcss.js.map +0 -1
- package/postcss.mjs +0 -44
- package/postcss.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changes to CSS Has 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
|
+
- Updated: documentation
|
|
17
|
+
|
|
18
|
+
**Migrating to 3.0.0**
|
|
19
|
+
|
|
20
|
+
PostCSS plugin :
|
|
21
|
+
|
|
22
|
+
```diff
|
|
23
|
+
- const postcssHasPseudo = require('css-has-pseudo/postcss');
|
|
24
|
+
+ const postcssHasPseudo = require('css-has-pseudo');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Browser Polyfill :
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
- const cssHasPseudo = require('css-has-pseudo');
|
|
31
|
+
+ const cssHasPseudo = require('css-has-pseudo/browser');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
_The old CND url is now deprecated and will be removed in a next major release._
|
|
35
|
+
_It will continue to work for now._
|
|
36
|
+
|
|
37
|
+
```diff
|
|
38
|
+
- <script src="https://unpkg.com/css-has-pseudo/browser"></script>
|
|
39
|
+
+ <script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2.0.0 (September 16, 2021)
|
|
43
|
+
|
|
44
|
+
- Updated: Support for PostCS 8+ (major).
|
|
45
|
+
- Updated: Support for Node 12+ (major).
|
|
46
|
+
|
|
3
47
|
### 1.0.0 (June 10, 2019)
|
|
4
48
|
|
|
5
49
|
- Updated: `postcss-selector-parser` to 6.0.2 (major)
|
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# CSS Has Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Has 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 Has Pseudo] lets you style elements relative to other elements in CSS,
|
|
8
7
|
following the [Selectors Level 4] specification.
|
|
9
8
|
|
|
9
|
+
[](https://caniuse.com/#feat=css-has)
|
|
10
|
+
|
|
10
11
|
```css
|
|
11
12
|
a:has(> img) {
|
|
12
13
|
/* style links that contain an image */
|
|
@@ -30,21 +31,29 @@ body:has(:focus) {
|
|
|
30
31
|
From the command line, transform CSS files that use `:has` selectors:
|
|
31
32
|
|
|
32
33
|
```bash
|
|
33
|
-
npx css-has-pseudo SOURCE.css TRANSFORMED.css
|
|
34
|
+
npx css-has-pseudo SOURCE.css --output TRANSFORMED.css
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
Next, use your transformed CSS with this script:
|
|
37
38
|
|
|
38
39
|
```html
|
|
39
40
|
<link rel="stylesheet" href="TRANSFORMED.css">
|
|
40
|
-
<script src="https://unpkg.com/css-has-pseudo/browser"></script>
|
|
41
|
+
<script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
|
|
41
42
|
<script>cssHasPseudo(document)</script>
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
⚠️ Please use a versioned url, like this : `https://unpkg.com/css-has-pseudo@3.0.0/dist/browser-global.js`
|
|
46
|
+
Without the version, you might unexpectedly get a new major version of the library with breaking changes.
|
|
47
|
+
|
|
48
|
+
⚠️ If you were using an older version via a CDN, please update the entire url.
|
|
49
|
+
The old URL will no longer work in a future release.
|
|
50
|
+
|
|
51
|
+
That’s it. The script is 765 bytes and works in most browser versions, including
|
|
45
52
|
Internet Explorer 11. With a [Mutation Observer polyfill], the script will work
|
|
46
53
|
down to Internet Explorer 9.
|
|
47
54
|
|
|
55
|
+
See [README BROWSER](README-BROWSER.md) for more information.
|
|
56
|
+
|
|
48
57
|
## How it works
|
|
49
58
|
|
|
50
59
|
The [PostCSS plugin](README-POSTCSS.md) clones rules containing `:has`,
|
|
@@ -87,13 +96,11 @@ elements otherwise matching `:has` natively.
|
|
|
87
96
|
</body>
|
|
88
97
|
```
|
|
89
98
|
|
|
90
|
-
[cli-img]: https://img.shields.io/travis/csstools/css-has-pseudo/master.svg
|
|
91
|
-
[cli-url]: https://travis-ci.org/csstools/css-has-pseudo
|
|
92
99
|
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
|
93
100
|
[git-url]: https://gitter.im/postcss/postcss
|
|
94
101
|
[npm-img]: https://img.shields.io/npm/v/css-has-pseudo.svg
|
|
95
102
|
[npm-url]: https://www.npmjs.com/package/css-has-pseudo
|
|
96
103
|
|
|
97
|
-
[CSS Has Pseudo]: https://github.com/csstools/css-has-pseudo
|
|
104
|
+
[CSS Has Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo
|
|
98
105
|
[Mutation Observer polyfill]: https://github.com/webmodules/mutation-observer
|
|
99
106
|
[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#has-pseudo
|
package/browser.js
CHANGED
|
@@ -1,2 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
(function () {
|
|
2
|
+
|
|
3
|
+
/* global MutationObserver,requestAnimationFrame */
|
|
4
|
+
function cssHasPseudo(document) {
|
|
5
|
+
var observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
6
|
+
|
|
7
|
+
var attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
8
|
+
|
|
9
|
+
[].forEach.call(document.styleSheets, walkStyleSheet);
|
|
10
|
+
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
11
|
+
|
|
12
|
+
var mutationObserver = new MutationObserver(function (mutationsList) {
|
|
13
|
+
mutationsList.forEach(function (mutation) {
|
|
14
|
+
[].forEach.call(mutation.addedNodes || [], function (node) {
|
|
15
|
+
// walk stylesheets to collect observed css rules
|
|
16
|
+
if (node.nodeType === 1 && node.sheet) {
|
|
17
|
+
walkStyleSheet(node.sheet);
|
|
18
|
+
}
|
|
19
|
+
}); // transform observed css rules
|
|
20
|
+
|
|
21
|
+
cleanupObservedCssRules();
|
|
22
|
+
transformObservedItems();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
mutationObserver.observe(document, {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
}); // observe DOM events that affect pseudo-selectors
|
|
29
|
+
|
|
30
|
+
document.addEventListener('focus', transformObservedItems, true);
|
|
31
|
+
document.addEventListener('blur', transformObservedItems, true);
|
|
32
|
+
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
33
|
+
|
|
34
|
+
function transformObservedItems() {
|
|
35
|
+
requestAnimationFrame(function () {
|
|
36
|
+
observedItems.forEach(function (item) {
|
|
37
|
+
var nodes = [];
|
|
38
|
+
[].forEach.call(document.querySelectorAll(item.scopeSelector), function (element) {
|
|
39
|
+
var nthChild = [].indexOf.call(element.parentNode.children, element) + 1;
|
|
40
|
+
var relativeSelectors = item.relativeSelectors.map(function (relativeSelector) {
|
|
41
|
+
return item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector;
|
|
42
|
+
}).join(); // find any relative :has element from the :scope element
|
|
43
|
+
|
|
44
|
+
var relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
45
|
+
var shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
46
|
+
|
|
47
|
+
if (shouldElementMatch) {
|
|
48
|
+
// memorize the node
|
|
49
|
+
nodes.push(element); // set an attribute with an irregular attribute name
|
|
50
|
+
// document.createAttribute() doesn't support special characters
|
|
51
|
+
|
|
52
|
+
attributeElement.innerHTML = '<x ' + item.attributeName + '>';
|
|
53
|
+
element.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode()); // trigger a style refresh in IE and Edge
|
|
54
|
+
|
|
55
|
+
document.documentElement.style.zoom = 1;
|
|
56
|
+
document.documentElement.style.zoom = null;
|
|
57
|
+
}
|
|
58
|
+
}); // remove the encoded attribute from all nodes that no longer match them
|
|
59
|
+
|
|
60
|
+
item.nodes.forEach(function (node) {
|
|
61
|
+
if (nodes.indexOf(node) === -1) {
|
|
62
|
+
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
63
|
+
|
|
64
|
+
document.documentElement.style.zoom = 1;
|
|
65
|
+
document.documentElement.style.zoom = null;
|
|
66
|
+
}
|
|
67
|
+
}); // update the
|
|
68
|
+
|
|
69
|
+
item.nodes = nodes;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
} // remove any observed cssrules that no longer apply
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function cleanupObservedCssRules() {
|
|
76
|
+
[].push.apply(observedItems, observedItems.splice(0).filter(function (item) {
|
|
77
|
+
return item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode);
|
|
78
|
+
}));
|
|
79
|
+
} // walk a stylesheet to collect observed css rules
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function walkStyleSheet(styleSheet) {
|
|
83
|
+
try {
|
|
84
|
+
// walk a css rule to collect observed css rules
|
|
85
|
+
[].forEach.call(styleSheet.cssRules || [], function (rule) {
|
|
86
|
+
if (rule.selectorText) {
|
|
87
|
+
// decode the selector text in all browsers to:
|
|
88
|
+
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
89
|
+
var selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
90
|
+
|
|
91
|
+
if (selectors) {
|
|
92
|
+
var attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
93
|
+
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
94
|
+
observedItems.push({
|
|
95
|
+
rule: rule,
|
|
96
|
+
scopeSelector: selectors[1],
|
|
97
|
+
isNot: selectors[2],
|
|
98
|
+
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
99
|
+
attributeName: attributeName,
|
|
100
|
+
nodes: []
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
walkStyleSheet(rule);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
/* do nothing and continue */
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* global self */
|
|
114
|
+
self.cssHasPseudo = cssHasPseudo;
|
|
115
|
+
|
|
116
|
+
})();
|
|
117
|
+
//# sourceMappingURL=browser-global.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
|
|
3
|
+
/* global MutationObserver,requestAnimationFrame */
|
|
4
|
+
function cssHasPseudo(document) {
|
|
5
|
+
var observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
6
|
+
|
|
7
|
+
var attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
8
|
+
|
|
9
|
+
[].forEach.call(document.styleSheets, walkStyleSheet);
|
|
10
|
+
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
11
|
+
|
|
12
|
+
var mutationObserver = new MutationObserver(function (mutationsList) {
|
|
13
|
+
mutationsList.forEach(function (mutation) {
|
|
14
|
+
[].forEach.call(mutation.addedNodes || [], function (node) {
|
|
15
|
+
// walk stylesheets to collect observed css rules
|
|
16
|
+
if (node.nodeType === 1 && node.sheet) {
|
|
17
|
+
walkStyleSheet(node.sheet);
|
|
18
|
+
}
|
|
19
|
+
}); // transform observed css rules
|
|
20
|
+
|
|
21
|
+
cleanupObservedCssRules();
|
|
22
|
+
transformObservedItems();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
mutationObserver.observe(document, {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
}); // observe DOM events that affect pseudo-selectors
|
|
29
|
+
|
|
30
|
+
document.addEventListener('focus', transformObservedItems, true);
|
|
31
|
+
document.addEventListener('blur', transformObservedItems, true);
|
|
32
|
+
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
33
|
+
|
|
34
|
+
function transformObservedItems() {
|
|
35
|
+
requestAnimationFrame(function () {
|
|
36
|
+
observedItems.forEach(function (item) {
|
|
37
|
+
var nodes = [];
|
|
38
|
+
[].forEach.call(document.querySelectorAll(item.scopeSelector), function (element) {
|
|
39
|
+
var nthChild = [].indexOf.call(element.parentNode.children, element) + 1;
|
|
40
|
+
var relativeSelectors = item.relativeSelectors.map(function (relativeSelector) {
|
|
41
|
+
return item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector;
|
|
42
|
+
}).join(); // find any relative :has element from the :scope element
|
|
43
|
+
|
|
44
|
+
var relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
45
|
+
var shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
46
|
+
|
|
47
|
+
if (shouldElementMatch) {
|
|
48
|
+
// memorize the node
|
|
49
|
+
nodes.push(element); // set an attribute with an irregular attribute name
|
|
50
|
+
// document.createAttribute() doesn't support special characters
|
|
51
|
+
|
|
52
|
+
attributeElement.innerHTML = '<x ' + item.attributeName + '>';
|
|
53
|
+
element.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode()); // trigger a style refresh in IE and Edge
|
|
54
|
+
|
|
55
|
+
document.documentElement.style.zoom = 1;
|
|
56
|
+
document.documentElement.style.zoom = null;
|
|
57
|
+
}
|
|
58
|
+
}); // remove the encoded attribute from all nodes that no longer match them
|
|
59
|
+
|
|
60
|
+
item.nodes.forEach(function (node) {
|
|
61
|
+
if (nodes.indexOf(node) === -1) {
|
|
62
|
+
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
63
|
+
|
|
64
|
+
document.documentElement.style.zoom = 1;
|
|
65
|
+
document.documentElement.style.zoom = null;
|
|
66
|
+
}
|
|
67
|
+
}); // update the
|
|
68
|
+
|
|
69
|
+
item.nodes = nodes;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
} // remove any observed cssrules that no longer apply
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function cleanupObservedCssRules() {
|
|
76
|
+
[].push.apply(observedItems, observedItems.splice(0).filter(function (item) {
|
|
77
|
+
return item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode);
|
|
78
|
+
}));
|
|
79
|
+
} // walk a stylesheet to collect observed css rules
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function walkStyleSheet(styleSheet) {
|
|
83
|
+
try {
|
|
84
|
+
// walk a css rule to collect observed css rules
|
|
85
|
+
[].forEach.call(styleSheet.cssRules || [], function (rule) {
|
|
86
|
+
if (rule.selectorText) {
|
|
87
|
+
// decode the selector text in all browsers to:
|
|
88
|
+
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
89
|
+
var selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
90
|
+
|
|
91
|
+
if (selectors) {
|
|
92
|
+
var attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
93
|
+
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
94
|
+
observedItems.push({
|
|
95
|
+
rule: rule,
|
|
96
|
+
scopeSelector: selectors[1],
|
|
97
|
+
isNot: selectors[2],
|
|
98
|
+
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
99
|
+
attributeName: attributeName,
|
|
100
|
+
nodes: []
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
walkStyleSheet(rule);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
/* do nothing and continue */
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* global self */
|
|
114
|
+
self.cssHasPseudo = cssHasPseudo;
|
|
115
|
+
|
|
116
|
+
})();
|
|
117
|
+
//# 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,requestAnimationFrame */\nexport default function cssHasPseudo(document) {\n\tconst observedItems = [];\n\n\t// document.createAttribute() doesn't support `:` in the name. innerHTML does\n\tconst attributeElement = document.createElement('x');\n\n\t// walk all stylesheets to collect observed css rules\n\t[].forEach.call(document.styleSheets, walkStyleSheet);\n\ttransformObservedItems();\n\n\t// observe DOM modifications that affect selectors\n\tconst mutationObserver = new MutationObserver(mutationsList => {\n\t\tmutationsList.forEach(mutation => {\n\t\t\t[].forEach.call(mutation.addedNodes || [], node => {\n\t\t\t\t// walk stylesheets to collect observed css rules\n\t\t\t\tif (node.nodeType === 1 && node.sheet) {\n\t\t\t\t\twalkStyleSheet(node.sheet);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// transform observed css rules\n\t\t\tcleanupObservedCssRules();\n\t\t\ttransformObservedItems();\n\t\t});\n\t});\n\n\tmutationObserver.observe(document, { childList: true, subtree: true });\n\n\t// observe DOM events that affect pseudo-selectors\n\tdocument.addEventListener('focus', transformObservedItems, true);\n\tdocument.addEventListener('blur', transformObservedItems, true);\n\tdocument.addEventListener('input', transformObservedItems);\n\n\t// transform observed css rules\n\tfunction transformObservedItems () {\n\t\trequestAnimationFrame(() => {\n\t\t\tobservedItems.forEach(\n\t\t\t\titem => {\n\t\t\t\t\tconst nodes = [];\n\n\t\t\t\t\t[].forEach.call(\n\t\t\t\t\t\tdocument.querySelectorAll(item.scopeSelector),\n\t\t\t\t\t\telement => {\n\t\t\t\t\t\t\tconst nthChild = [].indexOf.call(element.parentNode.children, element) + 1;\n\t\t\t\t\t\t\tconst relativeSelectors = item.relativeSelectors.map(\n\t\t\t\t\t\t\t\trelativeSelector => item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector,\n\t\t\t\t\t\t\t).join();\n\n\t\t\t\t\t\t\t// find any relative :has element from the :scope element\n\t\t\t\t\t\t\tconst relativeElement = element.parentNode.querySelector(relativeSelectors);\n\n\t\t\t\t\t\t\tconst shouldElementMatch = item.isNot ? !relativeElement : relativeElement;\n\n\t\t\t\t\t\t\tif (shouldElementMatch) {\n\t\t\t\t\t\t\t\t// memorize the node\n\t\t\t\t\t\t\t\tnodes.push(element);\n\n\t\t\t\t\t\t\t\t// set an attribute with an irregular attribute name\n\t\t\t\t\t\t\t\t// document.createAttribute() doesn't support special characters\n\t\t\t\t\t\t\t\tattributeElement.innerHTML = '<x ' + item.attributeName + '>';\n\n\t\t\t\t\t\t\t\telement.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode());\n\n\t\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\t// remove the encoded attribute from all nodes that no longer match them\n\t\t\t\t\titem.nodes.forEach(node => {\n\t\t\t\t\t\tif (nodes.indexOf(node) === -1) {\n\t\t\t\t\t\t\tnode.removeAttribute(item.attributeName);\n\n\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\t// update the\n\t\t\t\t\titem.nodes = nodes;\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// remove any observed cssrules that no longer apply\n\tfunction cleanupObservedCssRules () {\n\t\t[].push.apply(\n\t\t\tobservedItems,\n\t\t\tobservedItems.splice(0).filter(\n\t\t\t\titem => item.rule.parentStyleSheet &&\n\t\t\t\t\titem.rule.parentStyleSheet.ownerNode &&\n\t\t\t\t\tdocument.documentElement.contains(item.rule.parentStyleSheet.ownerNode),\n\t\t\t),\n\t\t);\n\t}\n\n\t// walk a stylesheet to collect observed css rules\n\tfunction walkStyleSheet (styleSheet) {\n\t\ttry {\n\t\t\t// walk a css rule to collect observed css rules\n\t\t\t[].forEach.call(styleSheet.cssRules || [], rule => {\n\t\t\t\tif (rule.selectorText) {\n\t\t\t\t\t// decode the selector text in all browsers to:\n\t\t\t\t\t// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative\n\t\t\t\t\tconst selectors = decodeURIComponent(rule.selectorText.replace(/\\\\(.)/g, '$1')).match(/^(.*?)\\[:(not-)?has\\((.+?)\\)\\](.*?)$/);\n\n\t\t\t\t\tif (selectors) {\n\t\t\t\t\t\tconst attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' +\n\t\t\t\t\t\t\t// encode a :has() pseudo selector as an attribute name\n\t\t\t\t\t\t\tencodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') +\n\t\t\t\t\t\t')';\n\n\t\t\t\t\t\tobservedItems.push({\n\t\t\t\t\t\t\trule,\n\t\t\t\t\t\t\tscopeSelector: selectors[1],\n\t\t\t\t\t\t\tisNot: selectors[2],\n\t\t\t\t\t\t\trelativeSelectors: selectors[3].split(/\\s*,\\s*/),\n\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\tnodes: [],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\twalkStyleSheet(rule);\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t/* do nothing and continue */\n\t\t}\n\t}\n}\n","/* global self */\nimport { default as cssHasPseudo } from './browser';\nself.cssHasPseudo = cssHasPseudo;\n"],"names":["cssHasPseudo","document","observedItems","attributeElement","createElement","forEach","call","styleSheets","walkStyleSheet","transformObservedItems","mutationObserver","MutationObserver","mutationsList","mutation","addedNodes","node","nodeType","sheet","cleanupObservedCssRules","observe","childList","subtree","addEventListener","requestAnimationFrame","item","nodes","querySelectorAll","scopeSelector","element","nthChild","indexOf","parentNode","children","relativeSelectors","map","relativeSelector","join","relativeElement","querySelector","shouldElementMatch","isNot","push","innerHTML","attributeName","setAttributeNode","attributes","cloneNode","documentElement","style","zoom","removeAttribute","apply","splice","filter","rule","parentStyleSheet","ownerNode","contains","styleSheet","cssRules","selectorText","selectors","decodeURIComponent","replace","match","encodeURICompon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AA8DC,KAA9D,CAAoE,sCAApE,CAAlB;;CAEA,cAAIH,SAAJ,EAAe;CACd,gBAAMlB,aAAa,GAAG,OAAOkB,SAAS,CAAC,CAAD,CAAT,GAAe,MAAf,GAAwB,EAA/B,IAAqC,MAArC;CAErBI,YAAAA,kBAAkB,CAACJ,SAAS,CAAC,CAAD,CAAV,CAAlB,CAAiCE,OAAjC,CAAyC,MAAzC,EAAiD,GAAjD,EAAsDA,OAAtD,CAA8D,MAA9D,EAAsE,GAAtE,EAA2EA,OAA3E,CAAmF,MAAnF,EAA2F,GAA3F,EAAgGA,OAAhG,CAAwG,MAAxG,EAAgH,GAAhH,CAFqB,GAGtB,GAHA;CAKA7D,YAAAA,aAAa,CAACuC,IAAd,CAAmB;CAClBa,cAAAA,IAAI,EAAJA,IADkB;CAElB3B,cAAAA,aAAa,EAAEkC,SAAS,CAAC,CAAD,CAFN;CAGlBrB,cAAAA,KAAK,EAAEqB,SAAS,CAAC,CAAD,CAHE;CAIlB5B,cAAAA,iBAAiB,EAAE4B,SAAS,CAAC,CAAD,CAAT,CAAaK,KAAb,CAAmB,SAAnB,CAJD;CAKlBvB,cAAAA,aAAa,EAAbA,aALkB;CAMlBlB,cAAAA,KAAK,EAAE;CANW,aAAnB;CAQA;CACD,SApBD,MAoBO;CACNjB,UAAAA,cAAc,CAAC8C,IAAD,CAAd;CACA;CACD,OAxBD;CAyBA,KA3BD,CA2BE,OAAOa,KAAP,EAAc;CACf;CACA;CACD;CACD;;CCpID;CAEAC,IAAI,CAACpE,YAAL,GAAoBA,YAApB;;;;;;"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* global MutationObserver,requestAnimationFrame */
|
|
3
2
|
function cssHasPseudo(document) {
|
|
4
|
-
|
|
3
|
+
var observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
var attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
7
6
|
|
|
8
7
|
[].forEach.call(document.styleSheets, walkStyleSheet);
|
|
9
8
|
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
mutationsList.forEach(mutation
|
|
13
|
-
[].forEach.call(mutation.addedNodes || [], node
|
|
10
|
+
var mutationObserver = new MutationObserver(function (mutationsList) {
|
|
11
|
+
mutationsList.forEach(function (mutation) {
|
|
12
|
+
[].forEach.call(mutation.addedNodes || [], function (node) {
|
|
14
13
|
// walk stylesheets to collect observed css rules
|
|
15
14
|
if (node.nodeType === 1 && node.sheet) {
|
|
16
15
|
walkStyleSheet(node.sheet);
|
|
@@ -31,15 +30,17 @@ function cssHasPseudo(document) {
|
|
|
31
30
|
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
32
31
|
|
|
33
32
|
function transformObservedItems() {
|
|
34
|
-
requestAnimationFrame(()
|
|
35
|
-
observedItems.forEach(item
|
|
36
|
-
|
|
37
|
-
[].forEach.call(document.querySelectorAll(item.scopeSelector), element
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
requestAnimationFrame(function () {
|
|
34
|
+
observedItems.forEach(function (item) {
|
|
35
|
+
var nodes = [];
|
|
36
|
+
[].forEach.call(document.querySelectorAll(item.scopeSelector), function (element) {
|
|
37
|
+
var nthChild = [].indexOf.call(element.parentNode.children, element) + 1;
|
|
38
|
+
var relativeSelectors = item.relativeSelectors.map(function (relativeSelector) {
|
|
39
|
+
return item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector;
|
|
40
|
+
}).join(); // find any relative :has element from the :scope element
|
|
41
|
+
|
|
42
|
+
var relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
43
|
+
var shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
43
44
|
|
|
44
45
|
if (shouldElementMatch) {
|
|
45
46
|
// memorize the node
|
|
@@ -54,7 +55,7 @@ function cssHasPseudo(document) {
|
|
|
54
55
|
}
|
|
55
56
|
}); // remove the encoded attribute from all nodes that no longer match them
|
|
56
57
|
|
|
57
|
-
item.nodes.forEach(node
|
|
58
|
+
item.nodes.forEach(function (node) {
|
|
58
59
|
if (nodes.indexOf(node) === -1) {
|
|
59
60
|
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
60
61
|
|
|
@@ -70,28 +71,30 @@ function cssHasPseudo(document) {
|
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
function cleanupObservedCssRules() {
|
|
73
|
-
[].push.apply(observedItems, observedItems.splice(0).filter(
|
|
74
|
+
[].push.apply(observedItems, observedItems.splice(0).filter(function (item) {
|
|
75
|
+
return item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode);
|
|
76
|
+
}));
|
|
74
77
|
} // walk a stylesheet to collect observed css rules
|
|
75
78
|
|
|
76
79
|
|
|
77
80
|
function walkStyleSheet(styleSheet) {
|
|
78
81
|
try {
|
|
79
82
|
// walk a css rule to collect observed css rules
|
|
80
|
-
[].forEach.call(styleSheet.cssRules || [], rule
|
|
83
|
+
[].forEach.call(styleSheet.cssRules || [], function (rule) {
|
|
81
84
|
if (rule.selectorText) {
|
|
82
85
|
// decode the selector text in all browsers to:
|
|
83
86
|
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
84
|
-
|
|
87
|
+
var selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
85
88
|
|
|
86
89
|
if (selectors) {
|
|
87
|
-
|
|
90
|
+
var attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
88
91
|
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
89
92
|
observedItems.push({
|
|
90
|
-
rule,
|
|
93
|
+
rule: rule,
|
|
91
94
|
scopeSelector: selectors[1],
|
|
92
95
|
isNot: selectors[2],
|
|
93
96
|
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
94
|
-
attributeName,
|
|
97
|
+
attributeName: attributeName,
|
|
95
98
|
nodes: []
|
|
96
99
|
});
|
|
97
100
|
}
|
|
@@ -106,4 +109,4 @@ function cssHasPseudo(document) {
|
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
module.exports = cssHasPseudo;
|
|
109
|
-
//# sourceMappingURL=
|
|
112
|
+
//# sourceMappingURL=browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["/* global MutationObserver,requestAnimationFrame */\nexport default function cssHasPseudo(document) {\n\tconst observedItems = [];\n\n\t// document.createAttribute() doesn't support `:` in the name. innerHTML does\n\tconst attributeElement = document.createElement('x');\n\n\t// walk all stylesheets to collect observed css rules\n\t[].forEach.call(document.styleSheets, walkStyleSheet);\n\ttransformObservedItems();\n\n\t// observe DOM modifications that affect selectors\n\tconst mutationObserver = new MutationObserver(mutationsList => {\n\t\tmutationsList.forEach(mutation => {\n\t\t\t[].forEach.call(mutation.addedNodes || [], node => {\n\t\t\t\t// walk stylesheets to collect observed css rules\n\t\t\t\tif (node.nodeType === 1 && node.sheet) {\n\t\t\t\t\twalkStyleSheet(node.sheet);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// transform observed css rules\n\t\t\tcleanupObservedCssRules();\n\t\t\ttransformObservedItems();\n\t\t});\n\t});\n\n\tmutationObserver.observe(document, { childList: true, subtree: true });\n\n\t// observe DOM events that affect pseudo-selectors\n\tdocument.addEventListener('focus', transformObservedItems, true);\n\tdocument.addEventListener('blur', transformObservedItems, true);\n\tdocument.addEventListener('input', transformObservedItems);\n\n\t// transform observed css rules\n\tfunction transformObservedItems () {\n\t\trequestAnimationFrame(() => {\n\t\t\tobservedItems.forEach(\n\t\t\t\titem => {\n\t\t\t\t\tconst nodes = [];\n\n\t\t\t\t\t[].forEach.call(\n\t\t\t\t\t\tdocument.querySelectorAll(item.scopeSelector),\n\t\t\t\t\t\telement => {\n\t\t\t\t\t\t\tconst nthChild = [].indexOf.call(element.parentNode.children, element) + 1;\n\t\t\t\t\t\t\tconst relativeSelectors = item.relativeSelectors.map(\n\t\t\t\t\t\t\t\trelativeSelector => item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector,\n\t\t\t\t\t\t\t).join();\n\n\t\t\t\t\t\t\t// find any relative :has element from the :scope element\n\t\t\t\t\t\t\tconst relativeElement = element.parentNode.querySelector(relativeSelectors);\n\n\t\t\t\t\t\t\tconst shouldElementMatch = item.isNot ? !relativeElement : relativeElement;\n\n\t\t\t\t\t\t\tif (shouldElementMatch) {\n\t\t\t\t\t\t\t\t// memorize the node\n\t\t\t\t\t\t\t\tnodes.push(element);\n\n\t\t\t\t\t\t\t\t// set an attribute with an irregular attribute name\n\t\t\t\t\t\t\t\t// document.createAttribute() doesn't support special characters\n\t\t\t\t\t\t\t\tattributeElement.innerHTML = '<x ' + item.attributeName + '>';\n\n\t\t\t\t\t\t\t\telement.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode());\n\n\t\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\t// remove the encoded attribute from all nodes that no longer match them\n\t\t\t\t\titem.nodes.forEach(node => {\n\t\t\t\t\t\tif (nodes.indexOf(node) === -1) {\n\t\t\t\t\t\t\tnode.removeAttribute(item.attributeName);\n\n\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\t// update the\n\t\t\t\t\titem.nodes = nodes;\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// remove any observed cssrules that no longer apply\n\tfunction cleanupObservedCssRules () {\n\t\t[].push.apply(\n\t\t\tobservedItems,\n\t\t\tobservedItems.splice(0).filter(\n\t\t\t\titem => item.rule.parentStyleSheet &&\n\t\t\t\t\titem.rule.parentStyleSheet.ownerNode &&\n\t\t\t\t\tdocument.documentElement.contains(item.rule.parentStyleSheet.ownerNode),\n\t\t\t),\n\t\t);\n\t}\n\n\t// walk a stylesheet to collect observed css rules\n\tfunction walkStyleSheet (styleSheet) {\n\t\ttry {\n\t\t\t// walk a css rule to collect observed css rules\n\t\t\t[].forEach.call(styleSheet.cssRules || [], rule => {\n\t\t\t\tif (rule.selectorText) {\n\t\t\t\t\t// decode the selector text in all browsers to:\n\t\t\t\t\t// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative\n\t\t\t\t\tconst selectors = decodeURIComponent(rule.selectorText.replace(/\\\\(.)/g, '$1')).match(/^(.*?)\\[:(not-)?has\\((.+?)\\)\\](.*?)$/);\n\n\t\t\t\t\tif (selectors) {\n\t\t\t\t\t\tconst attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' +\n\t\t\t\t\t\t\t// encode a :has() pseudo selector as an attribute name\n\t\t\t\t\t\t\tencodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') +\n\t\t\t\t\t\t')';\n\n\t\t\t\t\t\tobservedItems.push({\n\t\t\t\t\t\t\trule,\n\t\t\t\t\t\t\tscopeSelector: selectors[1],\n\t\t\t\t\t\t\tisNot: selectors[2],\n\t\t\t\t\t\t\trelativeSelectors: selectors[3].split(/\\s*,\\s*/),\n\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\tnodes: [],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\twalkStyleSheet(rule);\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t/* do nothing and continue */\n\t\t}\n\t}\n}\n"],"names":["cssHasPseudo","document","observedItems","attributeElement","createElement","forEach","call","styleSheets","walkStyleSheet","transformObservedItems","mutationObserver","MutationObserver","mutationsList","mutation","addedNodes","node","nodeType","sheet","cleanupObservedCssRules","observe","childList","subtree","addEventListener","requestAnimationFrame","item","nodes","querySelectorAll","scopeSelector","element","nthChild","indexOf","parentNode","children","relativeSelectors","map","relativeSelector","join","relativeElement","querySelector","shouldElementMatch","isNot","push","innerHTML","attributeName","setAttributeNode","attributes","cloneNode","documentElement","style","zoom","removeAttribute","apply","splice","filter","rule","parentStyleSheet","ownerNode","contains","styleSheet","cssRules","selectorText","selectors","decodeURIComponent","replace","match","encodeURIComponent","split","error"],"mappings":"AAAA;AACe,SAASA,YAAT,CAAsBC,QAAtB,EAAgC;AAC9C,MAAMC,aAAa,GAAG,EAAtB,CAD8C;;AAI9C,MAAMC,gBAAgB,GAAGF,QAAQ,CAACG,aAAT,CAAuB,GAAvB,CAAzB,CAJ8C;;AAO9C,KAAGC,OAAH,CAAWC,IAAX,CAAgBL,QAAQ,CAACM,WAAzB,EAAsCC,cAAtC;AACAC,EAAAA,sBAAsB,GARwB;;AAW9C,MAAMC,gBAAgB,GAAG,IAAIC,gBAAJ,CAAqB,UAAAC,aAAa,EAAI;AAC9DA,IAAAA,aAAa,CAACP,OAAd,CAAsB,UAAAQ,QAAQ,EAAI;AACjC,SAAGR,OAAH,CAAWC,IAAX,CAAgBO,QAAQ,CAACC,UAAT,IAAuB,EAAvC,EAA2C,UAAAC,IAAI,EAAI;AAClD;AACA,YAAIA,IAAI,CAACC,QAAL,KAAkB,CAAlB,IAAuBD,IAAI,CAACE,KAAhC,EAAuC;AACtCT,UAAAA,cAAc,CAACO,IAAI,CAACE,KAAN,CAAd;AACA;AACD,OALD,EADiC;;AASjCC,MAAAA,uBAAuB;AACvBT,MAA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,EAAbA,aALkB;AAMlBlB,cAAAA,KAAK,EAAE;AANW,aAAnB;AAQA;AACD,SApBD,MAoBO;AACNjB,UAAAA,cAAc,CAAC8C,IAAD,CAAd;AACA;AACD,OAxBD;AAyBA,KA3BD,CA2BE,OAAOa,KAAP,EAAc;AACf;AACA;AACD;AACD;;;;"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
/* global MutationObserver,requestAnimationFrame */
|
|
1
2
|
function cssHasPseudo(document) {
|
|
2
|
-
|
|
3
|
+
var observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
var attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
5
6
|
|
|
6
7
|
[].forEach.call(document.styleSheets, walkStyleSheet);
|
|
7
8
|
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
mutationsList.forEach(mutation
|
|
11
|
-
[].forEach.call(mutation.addedNodes || [], node
|
|
10
|
+
var mutationObserver = new MutationObserver(function (mutationsList) {
|
|
11
|
+
mutationsList.forEach(function (mutation) {
|
|
12
|
+
[].forEach.call(mutation.addedNodes || [], function (node) {
|
|
12
13
|
// walk stylesheets to collect observed css rules
|
|
13
14
|
if (node.nodeType === 1 && node.sheet) {
|
|
14
15
|
walkStyleSheet(node.sheet);
|
|
@@ -29,15 +30,17 @@ function cssHasPseudo(document) {
|
|
|
29
30
|
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
30
31
|
|
|
31
32
|
function transformObservedItems() {
|
|
32
|
-
requestAnimationFrame(()
|
|
33
|
-
observedItems.forEach(item
|
|
34
|
-
|
|
35
|
-
[].forEach.call(document.querySelectorAll(item.scopeSelector), element
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
requestAnimationFrame(function () {
|
|
34
|
+
observedItems.forEach(function (item) {
|
|
35
|
+
var nodes = [];
|
|
36
|
+
[].forEach.call(document.querySelectorAll(item.scopeSelector), function (element) {
|
|
37
|
+
var nthChild = [].indexOf.call(element.parentNode.children, element) + 1;
|
|
38
|
+
var relativeSelectors = item.relativeSelectors.map(function (relativeSelector) {
|
|
39
|
+
return item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector;
|
|
40
|
+
}).join(); // find any relative :has element from the :scope element
|
|
41
|
+
|
|
42
|
+
var relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
43
|
+
var shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
41
44
|
|
|
42
45
|
if (shouldElementMatch) {
|
|
43
46
|
// memorize the node
|
|
@@ -52,7 +55,7 @@ function cssHasPseudo(document) {
|
|
|
52
55
|
}
|
|
53
56
|
}); // remove the encoded attribute from all nodes that no longer match them
|
|
54
57
|
|
|
55
|
-
item.nodes.forEach(node
|
|
58
|
+
item.nodes.forEach(function (node) {
|
|
56
59
|
if (nodes.indexOf(node) === -1) {
|
|
57
60
|
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
58
61
|
|
|
@@ -68,28 +71,30 @@ function cssHasPseudo(document) {
|
|
|
68
71
|
|
|
69
72
|
|
|
70
73
|
function cleanupObservedCssRules() {
|
|
71
|
-
[].push.apply(observedItems, observedItems.splice(0).filter(
|
|
74
|
+
[].push.apply(observedItems, observedItems.splice(0).filter(function (item) {
|
|
75
|
+
return item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode);
|
|
76
|
+
}));
|
|
72
77
|
} // walk a stylesheet to collect observed css rules
|
|
73
78
|
|
|
74
79
|
|
|
75
80
|
function walkStyleSheet(styleSheet) {
|
|
76
81
|
try {
|
|
77
82
|
// walk a css rule to collect observed css rules
|
|
78
|
-
[].forEach.call(styleSheet.cssRules || [], rule
|
|
83
|
+
[].forEach.call(styleSheet.cssRules || [], function (rule) {
|
|
79
84
|
if (rule.selectorText) {
|
|
80
85
|
// decode the selector text in all browsers to:
|
|
81
86
|
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
82
|
-
|
|
87
|
+
var selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
83
88
|
|
|
84
89
|
if (selectors) {
|
|
85
|
-
|
|
90
|
+
var attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
86
91
|
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
87
92
|
observedItems.push({
|
|
88
|
-
rule,
|
|
93
|
+
rule: rule,
|
|
89
94
|
scopeSelector: selectors[1],
|
|
90
95
|
isNot: selectors[2],
|
|
91
96
|
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
92
|
-
attributeName,
|
|
97
|
+
attributeName: attributeName,
|
|
93
98
|
nodes: []
|
|
94
99
|
});
|
|
95
100
|
}
|
|
@@ -103,5 +108,5 @@ function cssHasPseudo(document) {
|
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
export default
|
|
107
|
-
//# sourceMappingURL=
|
|
111
|
+
export { cssHasPseudo as default };
|
|
112
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["/* global MutationObserver,requestAnimationFrame */\nexport default function cssHasPseudo(document) {\n\tconst observedItems = [];\n\n\t// document.createAttribute() doesn't support `:` in the name. innerHTML does\n\tconst attributeElement = document.createElement('x');\n\n\t// walk all stylesheets to collect observed css rules\n\t[].forEach.call(document.styleSheets, walkStyleSheet);\n\ttransformObservedItems();\n\n\t// observe DOM modifications that affect selectors\n\tconst mutationObserver = new MutationObserver(mutationsList => {\n\t\tmutationsList.forEach(mutation => {\n\t\t\t[].forEach.call(mutation.addedNodes || [], node => {\n\t\t\t\t// walk stylesheets to collect observed css rules\n\t\t\t\tif (node.nodeType === 1 && node.sheet) {\n\t\t\t\t\twalkStyleSheet(node.sheet);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// transform observed css rules\n\t\t\tcleanupObservedCssRules();\n\t\t\ttransformObservedItems();\n\t\t});\n\t});\n\n\tmutationObserver.observe(document, { childList: true, subtree: true });\n\n\t// observe DOM events that affect pseudo-selectors\n\tdocument.addEventListener('focus', transformObservedItems, true);\n\tdocument.addEventListener('blur', transformObservedItems, true);\n\tdocument.addEventListener('input', transformObservedItems);\n\n\t// transform observed css rules\n\tfunction transformObservedItems () {\n\t\trequestAnimationFrame(() => {\n\t\t\tobservedItems.forEach(\n\t\t\t\titem => {\n\t\t\t\t\tconst nodes = [];\n\n\t\t\t\t\t[].forEach.call(\n\t\t\t\t\t\tdocument.querySelectorAll(item.scopeSelector),\n\t\t\t\t\t\telement => {\n\t\t\t\t\t\t\tconst nthChild = [].indexOf.call(element.parentNode.children, element) + 1;\n\t\t\t\t\t\t\tconst relativeSelectors = item.relativeSelectors.map(\n\t\t\t\t\t\t\t\trelativeSelector => item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector,\n\t\t\t\t\t\t\t).join();\n\n\t\t\t\t\t\t\t// find any relative :has element from the :scope element\n\t\t\t\t\t\t\tconst relativeElement = element.parentNode.querySelector(relativeSelectors);\n\n\t\t\t\t\t\t\tconst shouldElementMatch = item.isNot ? !relativeElement : relativeElement;\n\n\t\t\t\t\t\t\tif (shouldElementMatch) {\n\t\t\t\t\t\t\t\t// memorize the node\n\t\t\t\t\t\t\t\tnodes.push(element);\n\n\t\t\t\t\t\t\t\t// set an attribute with an irregular attribute name\n\t\t\t\t\t\t\t\t// document.createAttribute() doesn't support special characters\n\t\t\t\t\t\t\t\tattributeElement.innerHTML = '<x ' + item.attributeName + '>';\n\n\t\t\t\t\t\t\t\telement.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode());\n\n\t\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\t// remove the encoded attribute from all nodes that no longer match them\n\t\t\t\t\titem.nodes.forEach(node => {\n\t\t\t\t\t\tif (nodes.indexOf(node) === -1) {\n\t\t\t\t\t\t\tnode.removeAttribute(item.attributeName);\n\n\t\t\t\t\t\t\t// trigger a style refresh in IE and Edge\n\t\t\t\t\t\t\tdocument.documentElement.style.zoom = 1; document.documentElement.style.zoom = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\t// update the\n\t\t\t\t\titem.nodes = nodes;\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// remove any observed cssrules that no longer apply\n\tfunction cleanupObservedCssRules () {\n\t\t[].push.apply(\n\t\t\tobservedItems,\n\t\t\tobservedItems.splice(0).filter(\n\t\t\t\titem => item.rule.parentStyleSheet &&\n\t\t\t\t\titem.rule.parentStyleSheet.ownerNode &&\n\t\t\t\t\tdocument.documentElement.contains(item.rule.parentStyleSheet.ownerNode),\n\t\t\t),\n\t\t);\n\t}\n\n\t// walk a stylesheet to collect observed css rules\n\tfunction walkStyleSheet (styleSheet) {\n\t\ttry {\n\t\t\t// walk a css rule to collect observed css rules\n\t\t\t[].forEach.call(styleSheet.cssRules || [], rule => {\n\t\t\t\tif (rule.selectorText) {\n\t\t\t\t\t// decode the selector text in all browsers to:\n\t\t\t\t\t// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative\n\t\t\t\t\tconst selectors = decodeURIComponent(rule.selectorText.replace(/\\\\(.)/g, '$1')).match(/^(.*?)\\[:(not-)?has\\((.+?)\\)\\](.*?)$/);\n\n\t\t\t\t\tif (selectors) {\n\t\t\t\t\t\tconst attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' +\n\t\t\t\t\t\t\t// encode a :has() pseudo selector as an attribute name\n\t\t\t\t\t\t\tencodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') +\n\t\t\t\t\t\t')';\n\n\t\t\t\t\t\tobservedItems.push({\n\t\t\t\t\t\t\trule,\n\t\t\t\t\t\t\tscopeSelector: selectors[1],\n\t\t\t\t\t\t\tisNot: selectors[2],\n\t\t\t\t\t\t\trelativeSelectors: selectors[3].split(/\\s*,\\s*/),\n\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\tnodes: [],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\twalkStyleSheet(rule);\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t/* do nothing and continue */\n\t\t}\n\t}\n}\n"],"names":["cssHasPseudo","document","observedItems","attributeElement","createElement","forEach","call","styleSheets","walkStyleSheet","transformObservedItems","mutationObserver","MutationObserver","mutationsList","mutation","addedNodes","node","nodeType","sheet","cleanupObservedCssRules","observe","childList","subtree","addEventListener","requestAnimationFrame","item","nodes","querySelectorAll","scopeSelector","element","nthChild","indexOf","parentNode","children","relativeSelectors","map","relativeSelector","join","relativeElement","querySelector","shouldElementMatch","isNot","push","innerHTML","attributeName","setAttributeNode","attributes","cloneNode","documentElement","style","zoom","removeAttribute","apply","splice","filter","rule","parentStyleSheet","ownerNode","contains","styleSheet","cssRules","selectorText","selectors","decodeURIComponent","replace","match","encodeURIComponent","split","error"],"mappings":"AAAA;AACe,SAASA,YAAT,CAAsBC,QAAtB,EAAgC;AAC9C,MAAMC,aAAa,GAAG,EAAtB,CAD8C;;AAI9C,MAAMC,gBAAgB,GAAGF,QAAQ,CAACG,aAAT,CAAuB,GAAvB,CAAzB,CAJ8C;;AAO9C,KAAGC,OAAH,CAAWC,IAAX,CAAgBL,QAAQ,CAACM,WAAzB,EAAs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