"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-selector-parser"));const r=/:dir\([^)]*\)/;function o(e){const o=Object(e).dir,s=Boolean(Object(e).preserve),a=Boolean(Object(e).shadow);return{postcssPlugin:"postcss-dir-pseudo-class",Rule(e,{result:l}){let n,c=!1;if(r.test(e.selector)){try{n=t.default((r=>{r.nodes.forEach((r=>{r.walk((r=>{if("pseudo"!==r.type)return;if(":dir"!==r.value)return;const s=r.nodes.toString();if("rtl"!==s&&"ltr"!==s)return;const n=r.parent;n.nodes.filter((e=>"pseudo"===e.type&&":dir"===e.value)).length>1&&!c&&(c=!0,e.warn(l,`Hierarchical :dir pseudo class usage can't be transformed correctly to [dir] attributes. This will lead to incorrect selectors for "${e.selector}"`));const u=r.prev(),p=r.next(),d=u&&u.type&&"combinator"!==u.type,i=p&&p.type&&"combinator"!==p.type,f=p&&p.type&&("combinator"!==p.type||"combinator"===p.type&&" "===p.value);d||i||0===n.nodes.indexOf(r)&&f||1===n.nodes.length?r.remove():r.replaceWith(t.default.universal());const v=n.nodes[0],b=v&&"combinator"===v.type&&" "===v.value,y=v&&"tag"===v.type&&"html"===v.value,h=v&&"pseudo"===v.type&&":root"===v.value;!v||y||h||b||n.prepend(t.default.combinator({value:" "}));const m=o===s,g=t.default.attribute({attribute:"dir",operator:"=",quoteMark:'"',value:`"${s}"`}),w=t.default.pseudo({value:":host-context"});w.append(g);const j=t.default.pseudo({value:(y||h?"":"html")+":not"});j.append(t.default.attribute({attribute:"dir",operator:"=",quoteMark:'"',value:`"${"ltr"===s?"rtl":"ltr"}"`})),m?y?n.insertAfter(v,j):n.prepend(j):y?n.insertAfter(v,g):a&&!h?n.prepend(w):n.prepend(g)}))}))})).processSync(e.selector)}catch(t){return void e.warn(l,`Failed to parse selector : ${e.selector}`)}void 0!==n&&n!==e.selector&&(s?e.cloneBefore({selector:n}):e.selector=n)}}}}o.postcss=!0,module.exports=o;
