import e from"postcss-selector-parser";const s="js-focus-visible",o=":focus-visible",creator=t=>{const r=Object.assign({preserve:!0,replaceWith:".focus-visible",disablePolyfillReadyClass:!1},t),n=e().astSync(r.replaceWith);return{postcssPlugin:"postcss-focus-visible",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-focus-visible",Rule(l,{result:a}){if(t.has(l))return;if(!l.selector.toLowerCase().includes(o))return;const i=l.selectors.flatMap(t=>{if(!t.toLowerCase().includes(o))return[t];let i;try{i=e().astSync(t)}catch(e){return l.warn(a,`Failed to parse selector : "${t}" with message: "${e instanceof Error?e.message:e}"`),t}if(void 0===i)return[t];let c=!1;if(i.walkPseudos(e=>{e.value.toLowerCase()===o&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(n.clone({}))))}),!c)return[t];const d=i.clone();if(!r.disablePolyfillReadyClass){if(i.nodes?.[0]?.nodes?.length)for(let o=0;o<i.nodes[0].nodes.length;o++){const t=i.nodes[0].nodes[o];if("combinator"===t.type||e.isPseudoElement(t)){i.nodes[0].insertBefore(t,e.className({value:s}));break}if(o===i.nodes[0].nodes.length-1){i.nodes[0].append(e.className({value:s}));break}}return i.nodes?.[0]?.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:s}))),[i.toString(),d.toString()]}return[i.toString()]});i.join(",")!==l.selectors.join(",")&&(t.add(l),l.cloneBefore({selectors:i}),r.preserve||l.remove())}}}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
