source: trip-planner-front/node_modules/postcss-pseudo-class-any-link/index.es.mjs@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import postcss from 'postcss';
2import parser from 'postcss-selector-parser';
3
4const anyAnyLinkMatch = /:any-link/;
5var index = postcss.plugin('postcss-pseudo-class-any-link', opts => {
6 const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
7 return root => {
8 // walk each matching rule
9 root.walkRules(anyAnyLinkMatch, rule => {
10 const rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector; // workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556
11
12 if (rawSelector[rawSelector.length - 1] !== ':') {
13 // update the selector
14 const updatedSelector = parser(selectors => {
15 // cache variables
16 let node;
17 let nodeIndex;
18 let selector;
19 let selectorLink;
20 let selectorVisited; // cache the selector index
21
22 let selectorIndex = -1; // for each selector
23
24 while (selector = selectors.nodes[++selectorIndex]) {
25 // reset the node index
26 nodeIndex = -1; // for each node
27
28 while (node = selector.nodes[++nodeIndex]) {
29 // if the node value matches the any-link value
30 if (node.value === ':any-link') {
31 // clone the selector
32 selectorLink = selector.clone();
33 selectorVisited = selector.clone(); // update the matching clone values
34
35 selectorLink.nodes[nodeIndex].value = ':link';
36 selectorVisited.nodes[nodeIndex].value = ':visited'; // replace the selector with the clones and roll back the selector index
37
38 selectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited); // stop updating the selector
39
40 break;
41 }
42 }
43 }
44 }).processSync(rawSelector);
45
46 if (updatedSelector !== rawSelector) {
47 if (preserve) {
48 rule.cloneBefore({
49 selector: updatedSelector
50 });
51 } else {
52 rule.selector = updatedSelector;
53 }
54 }
55 }
56 });
57 };
58});
59
60export default index;
61//# sourceMappingURL=index.es.mjs.map
Note: See TracBrowser for help on using the repository browser.