css-has-pseudo 0.9.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +14 -7
- package/browser.js +117 -1
- package/dist/browser-global.js +117 -0
- package/dist/browser-global.js.map +1 -0
- package/dist/browser.cjs +112 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/cli.mjs +3 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -47
- package/cli.js +0 -155
- package/index.js +0 -105
- package/index.js.map +0 -1
- package/index.mjs +0 -103
- 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/index.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function cssHasPseudo(document) {
|
|
4
|
-
const observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
5
|
-
|
|
6
|
-
const attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
7
|
-
|
|
8
|
-
Array.prototype.forEach.call(document.styleSheets, walkStyleSheet);
|
|
9
|
-
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
10
|
-
|
|
11
|
-
const mutationObserver = new MutationObserver(mutationsList => {
|
|
12
|
-
mutationsList.forEach(mutation => {
|
|
13
|
-
Array.prototype.forEach.call(mutation.addedNodes || [], node => {
|
|
14
|
-
// walk stylesheets to collect observed css rules
|
|
15
|
-
if (node.nodeType === 1 && node.sheet) {
|
|
16
|
-
walkStyleSheet(node.sheet);
|
|
17
|
-
}
|
|
18
|
-
}); // transform observed css rules
|
|
19
|
-
|
|
20
|
-
cleanupObservedCssRules();
|
|
21
|
-
transformObservedItems();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
mutationObserver.observe(document, {
|
|
25
|
-
childList: true,
|
|
26
|
-
subtree: true
|
|
27
|
-
}); // observe DOM events that affect pseudo-selectors
|
|
28
|
-
|
|
29
|
-
document.addEventListener('focus', transformObservedItems, true);
|
|
30
|
-
document.addEventListener('blur', transformObservedItems, true);
|
|
31
|
-
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
32
|
-
|
|
33
|
-
function transformObservedItems() {
|
|
34
|
-
requestAnimationFrame(() => {
|
|
35
|
-
observedItems.forEach(item => {
|
|
36
|
-
const nodes = [];
|
|
37
|
-
Array.prototype.forEach.call(document.querySelectorAll(item.scopeSelector), element => {
|
|
38
|
-
const nthChild = Array.prototype.indexOf.call(element.parentNode.children, element) + 1;
|
|
39
|
-
const relativeSelectors = item.relativeSelectors.map(relativeSelector => item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector).join(); // find any relative :has element from the :scope element
|
|
40
|
-
|
|
41
|
-
const relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
42
|
-
const shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
43
|
-
|
|
44
|
-
if (shouldElementMatch) {
|
|
45
|
-
// memorize the node
|
|
46
|
-
nodes.push(element); // set an attribute with an irregular attribute name
|
|
47
|
-
// document.createAttribute() doesn't support special characters
|
|
48
|
-
|
|
49
|
-
attributeElement.innerHTML = '<x ' + item.attributeName + '>';
|
|
50
|
-
element.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode()); // trigger a style refresh in IE and Edge
|
|
51
|
-
|
|
52
|
-
document.documentElement.style.zoom = 1;
|
|
53
|
-
document.documentElement.style.zoom = null;
|
|
54
|
-
}
|
|
55
|
-
}); // remove the encoded attribute from all nodes that no longer match them
|
|
56
|
-
|
|
57
|
-
item.nodes.forEach(node => {
|
|
58
|
-
if (nodes.indexOf(node) === -1) {
|
|
59
|
-
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
60
|
-
|
|
61
|
-
document.documentElement.style.zoom = 1;
|
|
62
|
-
document.documentElement.style.zoom = null;
|
|
63
|
-
}
|
|
64
|
-
}); // update the
|
|
65
|
-
|
|
66
|
-
item.nodes = nodes;
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
} // remove any observed cssrules that no longer apply
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
function cleanupObservedCssRules() {
|
|
73
|
-
Array.prototype.push.apply(observedItems, observedItems.splice(0).filter(item => item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode)));
|
|
74
|
-
} // walk a stylesheet to collect observed css rules
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
function walkStyleSheet(styleSheet) {
|
|
78
|
-
// walk a css rule to collect observed css rules
|
|
79
|
-
Array.prototype.forEach.call(styleSheet.cssRules || [], rule => {
|
|
80
|
-
if (rule.selectorText) {
|
|
81
|
-
// decode the selector text in all browsers to:
|
|
82
|
-
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
83
|
-
const selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
84
|
-
|
|
85
|
-
if (selectors) {
|
|
86
|
-
const attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
87
|
-
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
88
|
-
observedItems.push({
|
|
89
|
-
rule,
|
|
90
|
-
scopeSelector: selectors[1],
|
|
91
|
-
isNot: selectors[2],
|
|
92
|
-
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
93
|
-
attributeName,
|
|
94
|
-
nodes: []
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
walkStyleSheet(rule);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = cssHasPseudo;
|
|
105
|
-
//# sourceMappingURL=index.js.map
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["src/browser.js"],"sourcesContent":["export 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\tArray.prototype.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\tArray.prototype.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\tArray.prototype.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 = Array.prototype.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\tArray.prototype.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\t// walk a css rule to collect observed css rules\n\t\tArray.prototype.forEach.call(styleSheet.cssRules || [], rule => {\n\t\t\tif (rule.selectorText) {\n\t\t\t\t// decode the selector text in all browsers to:\n\t\t\t\t// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative\n\t\t\t\tconst selectors = decodeURIComponent(rule.selectorText.replace(/\\\\(.)/g, '$1')).match(/^(.*?)\\[:(not-)?has\\((.+?)\\)\\](.*?)$/);\n\n\t\t\t\tif (selectors) {\n\t\t\t\t\tconst attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' +\n\t\t\t\t\t\t// encode a :has() pseudo selector as an attribute name\n\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')';\n\n\t\t\t\t\tobservedItems.push({\n\t\t\t\t\t\trule,\n\t\t\t\t\t\tscopeSelector: selectors[1],\n\t\t\t\t\t\tisNot: selectors[2],\n\t\t\t\t\t\trelativeSelectors: selectors[3].split(/\\s*,\\s*/),\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tnodes: []\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twalkStyleSheet(rule);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"names":["cssHasPseudo","document","observedItems","attributeElement","createElement","Array","prototype","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"],"mappings":";;AAAe,SAASA,YAAT,CAAsBC,QAAtB,EAAgC;QACxCC,aAAa,GAAG,EAAtB,CAD8C;;QAIxCC,gBAAgB,GAAGF,QAAQ,CAACG,aAAT,CAAuB,GAAvB,CAAzB,CAJ8C;;EAO9CC,KAAK,CAACC,SAAN,CAAgBC,OAAhB,CAAwBC,IAAxB,CAA6BP,QAAQ,CAACQ,WAAtC,EAAmDC,cAAnD;EACAC,sBAAsB,GARwB;;QAWxCC,gBAAgB,GAAG,IAAIC,gBAAJ,CAAqBC,aAAa,IAAI;IAC9DA,aAAa,CAACP,OAAd,CAAsBQ,QAAQ,IAAI;MACjCV,KAAK,CAACC,SAAN,CAAgBC,OAAhB,CAAwBC,IAAxB,CAA6BO,QAAQ,CAACC,UAAT,IAAuB,EAApD,EAAwDC,IAAI,IAAI;;YAE3DA,IAAI,CAACC,QAAL,KAAkB,CAAlB,IAAuBD,IAAI,CAACE,KAAhC,EAAuC;UACtCT,cAAc,CAACO,IAAI,CAACE,KAAN,CAAd;;OAHF,EADiC;;MASjCC,uBAAuB;MACvBT,sBAAsB;KAVvB;GADwB,CAAzB;EAeAC,gBAAgB,CAACS,OAAjB,CAAyBpB,QAAzB,EAAmC;IAAEqB,SAAS,EAAE,IAAb;IAAmBC,OAAO,EAAE;GAA/D,EA1B8C;;EA6B9CtB,QAAQ,CAACuB,gBAAT,CAA0B,OAA1B,EAAmCb,sBAAnC,EAA2D,IAA3D;EACAV,QAAQ,CAACuB,gBAAT,CAA0B,MAA1B,EAAkCb,sBAAlC,EAA0D,IAA1D;EACAV,QAAQ,CAACuB,gBAAT,CAA0B,OAA1B,EAAmCb,sBAAnC,EA/B8C;;WAkCrCA,sBAAT,GAAkC;IACjCc,qBAAqB,CAAC,MAAM;MA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S,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;UAKA/D,aAAa,CAACyC,IAAd,CAAmB;YAClBa,IADkB;YAElB3B,aAAa,EAAEkC,SAAS,CAAC,CAAD,CAFN;YAGlBrB,KAAK,EAAEqB,SAAS,CAAC,CAAD,CAHE;YAIlB5B,iBAAiB,EAAE4B,SAAS,CAAC,CAAD,CAAT,CAAaK,KAAb,CAAmB,SAAnB,CAJD;YAKlBvB,aALkB;YAMlBlB,KAAK,EAAE;WANR;;OAXF,MAoBO;QACNjB,cAAc,CAAC8C,IAAD,CAAd;;KAtBF;;;;;;"}
|
package/index.mjs
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
function cssHasPseudo(document) {
|
|
2
|
-
const observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does
|
|
3
|
-
|
|
4
|
-
const attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules
|
|
5
|
-
|
|
6
|
-
Array.prototype.forEach.call(document.styleSheets, walkStyleSheet);
|
|
7
|
-
transformObservedItems(); // observe DOM modifications that affect selectors
|
|
8
|
-
|
|
9
|
-
const mutationObserver = new MutationObserver(mutationsList => {
|
|
10
|
-
mutationsList.forEach(mutation => {
|
|
11
|
-
Array.prototype.forEach.call(mutation.addedNodes || [], node => {
|
|
12
|
-
// walk stylesheets to collect observed css rules
|
|
13
|
-
if (node.nodeType === 1 && node.sheet) {
|
|
14
|
-
walkStyleSheet(node.sheet);
|
|
15
|
-
}
|
|
16
|
-
}); // transform observed css rules
|
|
17
|
-
|
|
18
|
-
cleanupObservedCssRules();
|
|
19
|
-
transformObservedItems();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
mutationObserver.observe(document, {
|
|
23
|
-
childList: true,
|
|
24
|
-
subtree: true
|
|
25
|
-
}); // observe DOM events that affect pseudo-selectors
|
|
26
|
-
|
|
27
|
-
document.addEventListener('focus', transformObservedItems, true);
|
|
28
|
-
document.addEventListener('blur', transformObservedItems, true);
|
|
29
|
-
document.addEventListener('input', transformObservedItems); // transform observed css rules
|
|
30
|
-
|
|
31
|
-
function transformObservedItems() {
|
|
32
|
-
requestAnimationFrame(() => {
|
|
33
|
-
observedItems.forEach(item => {
|
|
34
|
-
const nodes = [];
|
|
35
|
-
Array.prototype.forEach.call(document.querySelectorAll(item.scopeSelector), element => {
|
|
36
|
-
const nthChild = Array.prototype.indexOf.call(element.parentNode.children, element) + 1;
|
|
37
|
-
const relativeSelectors = item.relativeSelectors.map(relativeSelector => item.scopeSelector + ':nth-child(' + nthChild + ') ' + relativeSelector).join(); // find any relative :has element from the :scope element
|
|
38
|
-
|
|
39
|
-
const relativeElement = element.parentNode.querySelector(relativeSelectors);
|
|
40
|
-
const shouldElementMatch = item.isNot ? !relativeElement : relativeElement;
|
|
41
|
-
|
|
42
|
-
if (shouldElementMatch) {
|
|
43
|
-
// memorize the node
|
|
44
|
-
nodes.push(element); // set an attribute with an irregular attribute name
|
|
45
|
-
// document.createAttribute() doesn't support special characters
|
|
46
|
-
|
|
47
|
-
attributeElement.innerHTML = '<x ' + item.attributeName + '>';
|
|
48
|
-
element.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode()); // trigger a style refresh in IE and Edge
|
|
49
|
-
|
|
50
|
-
document.documentElement.style.zoom = 1;
|
|
51
|
-
document.documentElement.style.zoom = null;
|
|
52
|
-
}
|
|
53
|
-
}); // remove the encoded attribute from all nodes that no longer match them
|
|
54
|
-
|
|
55
|
-
item.nodes.forEach(node => {
|
|
56
|
-
if (nodes.indexOf(node) === -1) {
|
|
57
|
-
node.removeAttribute(item.attributeName); // trigger a style refresh in IE and Edge
|
|
58
|
-
|
|
59
|
-
document.documentElement.style.zoom = 1;
|
|
60
|
-
document.documentElement.style.zoom = null;
|
|
61
|
-
}
|
|
62
|
-
}); // update the
|
|
63
|
-
|
|
64
|
-
item.nodes = nodes;
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
} // remove any observed cssrules that no longer apply
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
function cleanupObservedCssRules() {
|
|
71
|
-
Array.prototype.push.apply(observedItems, observedItems.splice(0).filter(item => item.rule.parentStyleSheet && item.rule.parentStyleSheet.ownerNode && document.documentElement.contains(item.rule.parentStyleSheet.ownerNode)));
|
|
72
|
-
} // walk a stylesheet to collect observed css rules
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function walkStyleSheet(styleSheet) {
|
|
76
|
-
// walk a css rule to collect observed css rules
|
|
77
|
-
Array.prototype.forEach.call(styleSheet.cssRules || [], rule => {
|
|
78
|
-
if (rule.selectorText) {
|
|
79
|
-
// decode the selector text in all browsers to:
|
|
80
|
-
// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative
|
|
81
|
-
const selectors = decodeURIComponent(rule.selectorText.replace(/\\(.)/g, '$1')).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);
|
|
82
|
-
|
|
83
|
-
if (selectors) {
|
|
84
|
-
const attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' + // encode a :has() pseudo selector as an attribute name
|
|
85
|
-
encodeURIComponent(selectors[3]).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',') + ')';
|
|
86
|
-
observedItems.push({
|
|
87
|
-
rule,
|
|
88
|
-
scopeSelector: selectors[1],
|
|
89
|
-
isNot: selectors[2],
|
|
90
|
-
relativeSelectors: selectors[3].split(/\s*,\s*/),
|
|
91
|
-
attributeName,
|
|
92
|
-
nodes: []
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
walkStyleSheet(rule);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export default cssHasPseudo;
|
|
103
|
-
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["src/browser.js"],"sourcesContent":["export 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\tArray.prototype.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\tArray.prototype.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\tArray.prototype.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 = Array.prototype.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\tArray.prototype.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\t// walk a css rule to collect observed css rules\n\t\tArray.prototype.forEach.call(styleSheet.cssRules || [], rule => {\n\t\t\tif (rule.selectorText) {\n\t\t\t\t// decode the selector text in all browsers to:\n\t\t\t\t// [1] = :scope, [2] = :not(:has), [3] = :has relative, [4] = :scope relative\n\t\t\t\tconst selectors = decodeURIComponent(rule.selectorText.replace(/\\\\(.)/g, '$1')).match(/^(.*?)\\[:(not-)?has\\((.+?)\\)\\](.*?)$/);\n\n\t\t\t\tif (selectors) {\n\t\t\t\t\tconst attributeName = ':' + (selectors[2] ? 'not-' : '') + 'has(' +\n\t\t\t\t\t\t// encode a :has() pseudo selector as an attribute name\n\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')';\n\n\t\t\t\t\tobservedItems.push({\n\t\t\t\t\t\trule,\n\t\t\t\t\t\tscopeSelector: selectors[1],\n\t\t\t\t\t\tisNot: selectors[2],\n\t\t\t\t\t\trelativeSelectors: selectors[3].split(/\\s*,\\s*/),\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tnodes: []\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twalkStyleSheet(rule);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"names":["cssHasPseudo","document","observedItems","attributeElement","createElement","Array","prototype","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"],"mappings":"AAAe,SAASA,YAAT,CAAsBC,QAAtB,EAAgC;QACxCC,aAAa,GAAG,EAAtB,CAD8C;;QAIxCC,gBAAgB,GAAGF,QAAQ,CAACG,aAAT,CAAuB,GAAvB,CAAzB,CAJ8C;;EAO9CC,KAAK,CAACC,SAAN,CAAgBC,OAAhB,CAAwBC,IAAxB,CAA6BP,QAAQ,CAACQ,WAAtC,EAAmDC,cAAnD;EACAC,sBAAsB,GARwB;;QAWxCC,gBAAgB,GAAG,IAAIC,gBAAJ,CAAqBC,aAAa,IAAI;IAC9DA,aAAa,CAACP,OAAd,CAAsBQ,QAAQ,IAAI;MACjCV,KAAK,CAACC,SAAN,CAAgBC,OAAhB,CAAwBC,IAAxB,CAA6BO,QAAQ,CAACC,UAAT,IAAuB,EAApD,EAAwDC,IAAI,IAAI;;YAE3DA,IAAI,CAACC,QAAL,KAAkB,CAAlB,IAAuBD,IAAI,CAACE,KAAhC,EAAuC;UACtCT,cAAc,CAACO,IAAI,CAACE,KAAN,CAAd;;OAHF,EADiC;;MASjCC,uBAAuB;MACvBT,sBAAsB;KAVvB;GADwB,CAAzB;EAeAC,gBAAgB,CAACS,OAAjB,CAAyBpB,QAAzB,EAAmC;IAAEqB,SAAS,EAAE,IAAb;IAAmBC,OAAO,EAAE;GAA/D,EA1B8C;;EA6B9CtB,QAAQ,CAACuB,gBAAT,CAA0B,OAA1B,EAAmCb,sBAAnC,EAA2D,IAA3D;EACAV,QAAQ,CAACuB,gBAAT,CAA0B,MAA1B,EAAkCb,sBAAlC,EAA0D,IAA1D;EACAV,QAAQ,CAACuB,gBAAT,CAA0B,OAA1B,EAAmCb,sBAAnC,EA/B8C;;WAkCrCA,sBAAT,GAAkC;IACjCc,qBAAqB,CAAC,MAAM;M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AS,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;UAKA/D,aAAa,CAACyC,IAAd,CAAmB;YAClBa,IADkB;YAElB3B,aAAa,EAAEkC,SAAS,CAAC,CAAD,CAFN;YAGlBrB,KAAK,EAAEqB,SAAS,CAAC,CAAD,CAHE;YAIlB5B,iBAAiB,EAAE4B,SAAS,CAAC,CAAD,CAAT,CAAaK,KAAb,CAAmB,SAAnB,CAJD;YAKlBvB,aALkB;YAMlBlB,KAAK,EAAE;WANR;;OAXF,MAoBO;QACNjB,cAAc,CAAC8C,IAAD,CAAd;;KAtBF;;;;;;"}
|
package/postcss.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
var parser = _interopDefault(require('postcss-selector-parser'));
|
|
6
|
-
var postcss = _interopDefault(require('postcss'));
|
|
7
|
-
|
|
8
|
-
const selectorRegExp = /:has/;
|
|
9
|
-
var postcss$1 = postcss.plugin('css-has-pseudo', opts => {
|
|
10
|
-
const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
|
|
11
|
-
return root => {
|
|
12
|
-
root.walkRules(selectorRegExp, rule => {
|
|
13
|
-
const modifiedSelector = parser(selectors => {
|
|
14
|
-
selectors.walkPseudos(selector => {
|
|
15
|
-
if (selector.value === ':has' && selector.nodes) {
|
|
16
|
-
const isNotHas = checkIfParentIsNot(selector);
|
|
17
|
-
selector.value = isNotHas ? ':not-has' : ':has';
|
|
18
|
-
const attribute = parser.attribute({
|
|
19
|
-
attribute: encodeURIComponent(String(selector)).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%\[\],]/g, '\\$&')
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (isNotHas) {
|
|
23
|
-
selector.parent.parent.replaceWith(attribute);
|
|
24
|
-
} else {
|
|
25
|
-
selector.replaceWith(attribute);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}).processSync(rule.selector);
|
|
30
|
-
const clone = rule.clone({
|
|
31
|
-
selector: modifiedSelector
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (preserve) {
|
|
35
|
-
rule.before(clone);
|
|
36
|
-
} else {
|
|
37
|
-
rule.replaceWith(clone);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
function checkIfParentIsNot(selector) {
|
|
44
|
-
return Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = postcss$1;
|
|
48
|
-
//# sourceMappingURL=postcss.js.map
|
package/postcss.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postcss.js","sources":["src/postcss.js"],"sourcesContent":["import parser from 'postcss-selector-parser';\nimport postcss from 'postcss';\n\nconst selectorRegExp = /:has/;\n\nexport default postcss.plugin('css-has-pseudo', opts => {\n\tconst preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);\n\n\treturn root => {\n\t\troot.walkRules(selectorRegExp, rule => {\n\t\t\tconst modifiedSelector = parser(selectors => {\n\t\t\t\tselectors.walkPseudos(selector => {\n\t\t\t\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\t\t\t\tconst isNotHas = checkIfParentIsNot(selector);\n\t\t\t\t\t\tselector.value = isNotHas ? ':not-has' : ':has';\n\n\t\t\t\t\t\tconst attribute = parser.attribute({\n\t\t\t\t\t\t\tattribute: encodeURIComponent(String(selector))\n\t\t\t\t\t\t\t.replace(/%3A/g, ':')\n\t\t\t\t\t\t\t.replace(/%5B/g, '[')\n\t\t\t\t\t\t\t.replace(/%5D/g, ']')\n\t\t\t\t\t\t\t.replace(/%2C/g, ',')\n\t\t\t\t\t\t\t.replace(/[():%\\[\\],]/g, '\\\\$&')\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (isNotHas) {\n\t\t\t\t\t\t\tselector.parent.parent.replaceWith(attribute);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tselector.replaceWith(attribute);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}).processSync(rule.selector);\n\n\t\t\tconst clone = rule.clone({ selector: modifiedSelector });\n\n\t\t\tif (preserve) {\n\t\t\t\trule.before(clone);\n\t\t\t} else {\n\t\t\t\trule.replaceWith(clone);\n\t\t\t}\n\t\t});\n\t};\n});\n\nfunction checkIfParentIsNot(selector) {\n\treturn Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';\n}\n"],"names":["selectorRegExp","postcss","plugin","opts","preserve","Boolean","Object","root","walkRules","rule","modifiedSelector","parser","selectors","walkPseudos","selector","value","nodes","isNotHas","checkIfParentIsNot","attribute","encodeURIComponent","String","replace","parent","replaceWith","processSync","clone","before","type"],"mappings":";;;;;;;AAGA,MAAMA,cAAc,GAAG,MAAvB;AAEA,gBAAeC,OAAO,CAACC,MAAR,CAAe,gBAAf,EAAiCC,IAAI,IAAI;QACjDC,QAAQ,GAAGC,OAAO,CAAC,cAAcC,MAAM,CAACH,IAAD,CAApB,GAA6BA,IAAI,CAACC,QAAlC,GAA6C,IAA9C,CAAxB;SAEOG,IAAI,IAAI;IACdA,IAAI,CAACC,SAAL,CAAeR,cAAf,EAA+BS,IAAI,IAAI;YAChCC,gBAAgB,GAAGC,MAAM,CAACC,SAAS,IAAI;QAC5CA,SAAS,CAACC,WAAV,CAAsBC,QAAQ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
|
|
|
1
|
-
import parser from 'postcss-selector-parser';
|
|
2
|
-
import postcss from 'postcss';
|
|
3
|
-
|
|
4
|
-
const selectorRegExp = /:has/;
|
|
5
|
-
var postcss$1 = postcss.plugin('css-has-pseudo', opts => {
|
|
6
|
-
const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
|
|
7
|
-
return root => {
|
|
8
|
-
root.walkRules(selectorRegExp, rule => {
|
|
9
|
-
const modifiedSelector = parser(selectors => {
|
|
10
|
-
selectors.walkPseudos(selector => {
|
|
11
|
-
if (selector.value === ':has' && selector.nodes) {
|
|
12
|
-
const isNotHas = checkIfParentIsNot(selector);
|
|
13
|
-
selector.value = isNotHas ? ':not-has' : ':has';
|
|
14
|
-
const attribute = parser.attribute({
|
|
15
|
-
attribute: encodeURIComponent(String(selector)).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%\[\],]/g, '\\$&')
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (isNotHas) {
|
|
19
|
-
selector.parent.parent.replaceWith(attribute);
|
|
20
|
-
} else {
|
|
21
|
-
selector.replaceWith(attribute);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}).processSync(rule.selector);
|
|
26
|
-
const clone = rule.clone({
|
|
27
|
-
selector: modifiedSelector
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (preserve) {
|
|
31
|
-
rule.before(clone);
|
|
32
|
-
} else {
|
|
33
|
-
rule.replaceWith(clone);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
function checkIfParentIsNot(selector) {
|
|
40
|
-
return Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default postcss$1;
|
|
44
|
-
//# sourceMappingURL=postcss.mjs.map
|
package/postcss.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postcss.mjs","sources":["src/postcss.js"],"sourcesContent":["import parser from 'postcss-selector-parser';\nimport postcss from 'postcss';\n\nconst selectorRegExp = /:has/;\n\nexport default postcss.plugin('css-has-pseudo', opts => {\n\tconst preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);\n\n\treturn root => {\n\t\troot.walkRules(selectorRegExp, rule => {\n\t\t\tconst modifiedSelector = parser(selectors => {\n\t\t\t\tselectors.walkPseudos(selector => {\n\t\t\t\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\t\t\t\tconst isNotHas = checkIfParentIsNot(selector);\n\t\t\t\t\t\tselector.value = isNotHas ? ':not-has' : ':has';\n\n\t\t\t\t\t\tconst attribute = parser.attribute({\n\t\t\t\t\t\t\tattribute: encodeURIComponent(String(selector))\n\t\t\t\t\t\t\t.replace(/%3A/g, ':')\n\t\t\t\t\t\t\t.replace(/%5B/g, '[')\n\t\t\t\t\t\t\t.replace(/%5D/g, ']')\n\t\t\t\t\t\t\t.replace(/%2C/g, ',')\n\t\t\t\t\t\t\t.replace(/[():%\\[\\],]/g, '\\\\$&')\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (isNotHas) {\n\t\t\t\t\t\t\tselector.parent.parent.replaceWith(attribute);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tselector.replaceWith(attribute);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}).processSync(rule.selector);\n\n\t\t\tconst clone = rule.clone({ selector: modifiedSelector });\n\n\t\t\tif (preserve) {\n\t\t\t\trule.before(clone);\n\t\t\t} else {\n\t\t\t\trule.replaceWith(clone);\n\t\t\t}\n\t\t});\n\t};\n});\n\nfunction checkIfParentIsNot(selector) {\n\treturn Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';\n}\n"],"names":["selectorRegExp","postcss","plugin","opts","preserve","Boolean","Object","root","walkRules","rule","modifiedSelector","parser","selectors","walkPseudos","selector","value","nodes","isNotHas","checkIfParentIsNot","attribute","encodeURIComponent","String","replace","parent","replaceWith","processSync","clone","before","type"],"mappings":";;;AAGA,MAAMA,cAAc,GAAG,MAAvB;AAEA,gBAAeC,OAAO,CAACC,MAAR,CAAe,gBAAf,EAAiCC,IAAI,IAAI;QACjDC,QAAQ,GAAGC,OAAO,CAAC,cAAcC,MAAM,CAACH,IAAD,CAApB,GAA6BA,IAAI,CAACC,QAAlC,GAA6C,IAA9C,CAAxB;SAEOG,IAAI,IAAI;IACdA,IAAI,CAACC,SAAL,CAAeR,cAAf,EAA+BS,IAAI,IAAI;YAChCC,gBAAgB,GAAGC,MAAM,CAACC,SAAS,IAAI;QAC5CA,SAAS,CAACC,WAAV,CAAsBC,QAAQ,IAAI;cAC7BA,QAAQ,CAACC,KAAT,KAAmB,MAAnB,IAA6BD,QAAQ,CAACE,KAA1C,EAAiD;kBAC1CC,QAAQ,GAAGC,kBAAkB,CAACJ,QAAD,CAAnC;YACAA,QAAQ,CAACC,KAAT,GAAiBE,QAAQ,GAAG,UAAH,GAAgB,MAAzC;kBAEME,SAAS,GAAGR,MAAM,CAACQ,SAAP,CAAiB;cAClCA,SAAS,EAAEC,kBAAkB,CAACC,MAAM,CAACP,QAAD,CAAP,CAAlB,CACVQ,OADU,CACF,MADE,EACM,GADN,EAEVA,OAFU,CAEF,MAFE,EAEM,GAFN,EAGVA,OAHU,CAGF,MAHE,EAGM,GAHN,EAIVA,OAJU,CAIF,MAJE,EAIM,GAJN,EAKVA,OALU,CAKF,cALE,EAKc,MALd;aADM,CAAlB;;gBASIL,QAAJ,EAAc;cACbH,QAAQ,CAACS,MAAT,CAAgBA,MAAhB,CAAuBC,WAAvB,CAAmCL,SAAnC;aADD,MAEO;cACNL,QAAQ,CAACU,WAAT,CAAqBL,SAArB;;;SAjBH;OAD8B,CAAN,CAsBtBM,WAtBsB,CAsBVhB,IAAI,CAACK,QAtBK,CAAzB;YAwBMY,K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