import e from"postcss-selector-parser";const creator=t=>{const r=Object.assign({dir:null,preserve:!1,shadow:!1},t);return{postcssPlugin:"postcss-dir-pseudo-class",prepare(){const t=new WeakSet;return{postcssPlugin:"postcss-dir-pseudo-class",Rule(o,{result:s}){if(t.has(o))return;let a,n=!1;if(o.selector.toLowerCase().includes(":dir(")){try{a=e(t=>{t.nodes.forEach(t=>{t.walk(t=>{if("pseudo"!==t.type)return;if(":dir"!==t.value.toLowerCase())return;if(!t.nodes||!t.nodes.length)return;const a=t.nodes.toString().toLowerCase();if("rtl"!==a&&"ltr"!==a)return;const l=t.parent;if(!l)return;l.nodes.filter(e=>"pseudo"===e.type&&":dir"===e.value.toLowerCase()).length>1&&!n&&(n=!0,o.warn(s,`Hierarchical :dir pseudo class usage can't be transformed correctly to [dir] attributes. This will lead to incorrect selectors for "${o.selector}"`));const p=t.prev(),c=t.next(),i=p&&p.type&&"combinator"!==p.type,d=c&&c.type&&"combinator"!==c.type,u=c&&c.type&&("combinator"!==c.type||"combinator"===c.type&&" "===c.value);i||d||0===l.nodes.indexOf(t)&&u||1===l.nodes.length?t.remove():t.replaceWith(e.universal());const v=l.nodes[0],f=v&&"combinator"===v.type&&" "===v.value,w=v&&"tag"===v.type&&"html"===v.value.toLowerCase(),y=v&&"pseudo"===v.type&&":root"===v.value.toLowerCase();!v||w||y||f||l.prepend(e.combinator({value:" "}));const h=r.dir===a,m=e.attribute({attribute:"dir",operator:"=",quoteMark:'"',value:`"${a}"`,raws:{}}),b=e.pseudo({value:":host-context"});b.append(e.selector({value:"",nodes:[m]}));const g=e.pseudo({value:(w||y?"":"html")+":not"});g.append(e.selector({value:"",nodes:[e.attribute({attribute:"dir",operator:"=",quoteMark:'"',value:`"${"ltr"===a?"rtl":"ltr"}"`,raws:{}})]})),h?w?l.insertAfter(v,g):l.prepend(g):w?l.insertAfter(v,m):r.shadow&&!y?l.prepend(b):l.prepend(m)})})}).processSync(o.selector)}catch{return void o.warn(s,`Failed to parse selector : ${o.selector}`)}void 0!==a&&a!==o.selector&&(t.add(o),o.cloneBefore({selector:a}),r.preserve||o.remove())}}}}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
