source: trip-planner-front/node_modules/postcss-pseudo-class-any-link/index.cjs.js@ 1ad8e64

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

initial commit

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