"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-selector-parser"));function n(e){if(!e||!e.nodes)return;let n=[];const o=[...e.nodes];for(let e=0;e<o.length+1;e++){const l=o[e];if(l&&"combinator"!==l.type)n.push(l);else{if(n.length>1){const e=t.default.selector({value:""});n[0].replaceWith(e),n.slice(1).forEach((e=>{e.remove()})),n.forEach((t=>{e.append(t)})),s(e),e.replaceWith(...e.nodes)}n=[]}}}function s(e){e&&e.nodes&&e.nodes.sort(((e,t)=>"selector"===e.type&&"selector"===t.type&&e.nodes.length&&t.nodes.length?o(e.nodes[0],e.nodes[0].type)-o(t.nodes[0],t.nodes[0].type):"selector"===e.type&&e.nodes.length?o(e.nodes[0],e.nodes[0].type)-o(t,t.type):"selector"===t.type&&t.nodes.length?o(e,e.type)-o(t.nodes[0],t.nodes[0].type):o(e,e.type)-o(t,t.type)))}function o(e,n){return t.default.isPseudoElement(e)?l.pseudoElement:l[n]}const l={universal:0,tag:1,id:2,class:3,attribute:4,selector:5,pseudo:6,pseudoElement:7,string:8,root:9,comment:10},r=t.default().astSync(":link").nodes[0],c=t.default().astSync(":visited").nodes[0],u=t.default().astSync("area[href]").nodes[0],a=t.default().astSync("[href]").nodes[0];function d(e,s){let o=[];return t.default((e=>{let t=[];e.walkPseudos((e=>{if(":any-link"!==e.value||e.nodes&&e.nodes.length)return;if(!s)return void t.push([r.clone(),c.clone()]);const n=function(e){let t=[],n=e.prev();for(;n&&"combinator"!==n.type;)"tag"===n.type&&t.push(n.value),n=n.prev();let s=e.next();for(;s&&"combinator"!==s.type;)"tag"===s.type&&t.push(s.value),s=s.next();return t}(e);n.includes("area")?t.push([r.clone(),c.clone(),a.clone()]):n.length?t.push([r.clone(),c.clone()]):t.push([r.clone(),c.clone(),u.clone()])})),t.length&&function(...e){const t=[],n=e.length-1;function s(o,l){for(let r=0,c=e[l].length;r<c;r++){const c=o.slice(0);c.push(e[l][r]),l==n?t.push(c):s(c,l+1)}}return s([],0),t}(...t).forEach((t=>{const s=e.clone();s.walkPseudos((e=>{":any-link"!==e.value||e.nodes&&e.nodes.length||e.replaceWith(...t.shift().nodes)})),s.walk((e=>{"nodes"in e&&(e.nodes.forEach((e=>{n(e)})),n(e))})),o.push(s.toString())}))})).processSync(e),o}const i=/:any-link/;function p(e){const t={preserve:!0,...e},n={areaHrefNeedsFixing:!1,...Object(t.subFeatures)};return{postcssPlugin:"postcss-pseudo-class-any-link",Rule(e,{result:s}){if(!i.test(e.selector))return;const o=e.raws.selector&&e.raws.selector.raw||e.selector;":"!==o[o.length-1]&&function(e,t,n,s){let o=[],l=[];try{for(let t=0;t<e.selectors.length;t++){const n=e.selectors[t],r=d(n,s);r.length?o.push(...r):l.push(n)}}catch(n){return void e.warn(t,`Failed to parse selector : ${e.selector}`)}o.length&&(e.cloneBefore({selectors:o}),n?l.length&&e.cloneBefore({selectors:l}):l.length?e.selectors=l:e.remove())}(e,s,t.preserve,n.areaHrefNeedsFixing)}}}p.postcss=!0,module.exports=p;
