{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import parser from 'postcss-selector-parser';\n\nconst creator = (/** @type {{ preserve: true | false }} */ opts) => {\n\topts = typeof opts === 'object' && opts || defaultOptions;\n\n\t/** Whether the original rule should be preserved. */\n\tconst shouldPreserve = Boolean('preserve' in opts ? opts.preserve : true);\n\n\treturn {\n\t\tpostcssPlugin: 'css-has-pseudo',\n\t\tRule: (rule, { result }) => {\n\t\t\tif (!rule.selector.includes(':has(')) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet modifiedSelector;\n\n\t\t\ttry {\n\t\t\t\tconst modifiedSelectorAST = parser((selectors) => {\n\t\t\t\t\tselectors.walkPseudos(selector => {\n\t\t\t\t\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\t\t\t\t\tconst isNotHas = isParentInNotPseudo(selector);\n\n\t\t\t\t\t\t\tselector.value = isNotHas ? ':not-has' : ':has';\n\n\t\t\t\t\t\t\tconst attribute = parser.attribute({\n\t\t\t\t\t\t\t\tattribute: getEscapedCss(String(selector)),\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (isNotHas) {\n\t\t\t\t\t\t\t\tselector.parent.parent.replaceWith(attribute);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tselector.replaceWith(attribute);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}).processSync(rule.selector);\n\n\t\t\t\tmodifiedSelector = String(modifiedSelectorAST);\n\t\t\t} catch (_) {\n\t\t\t\trule.warn(result, `Failed to parse selector : ${rule.selector}`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (typeof modifiedSelector === 'undefined') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (modifiedSelector === rule.selector) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (shouldPreserve) {\n\t\t\t\trule.cloneBefore({ selector: modifiedSelector });\n\t\t\t} else {\n\t\t\t\trule.assign({ selector: modifiedSelector });\n\t\t\t}\n\t\t},\n\t};\n};\n\ncreator.postcss = true;\n\n/** Default options. */\nconst defaultOptions = { preserve: true };\n\n/** Returns the string as an escaped CSS identifier. */\nconst getEscapedCss = (/** @type {string} */ value) => encodeURIComponent(value).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%[\\],]/g, '\\\\$&');\n\n/** Returns whether the selector is within a `:not` pseudo-class. */\nconst isParentInNotPseudo = (selector) => selector.parent?.parent?.type === 'pseudo' && selector.parent.parent.value === ':not';\n\nexport default creator;\n"],"names":["creator","opts","defaultOptions","shouldPreserve","Boolean","preserve","postcssPlugin","Rule","rule","result","selector","includes","modifiedSelector","modifiedSelectorAST","parser","selectors","walkPseudos","value","nodes","isNotHas","isParentInNotPseudo","attribute","getEscapedCss","String","parent","replaceWith","processSync","_","warn","cloneBefore","assign","postcss","encodeURIComponent","replace","type"],"mappings":"uIAEMA,EAAqDC,IAC1DA,EAAuB,iBAATA,GAAqBA,GAAQC,QAGrCC,EAAiBC,UAAQ,aAAcH,IAAOA,EAAKI,gBAElD,CACNC,cAAe,iBACfC,KAAM,CAACC,GAAQC,OAAAA,UACTD,EAAKE,SAASC,SAAS,oBAIxBC,YAGGC,EAAsBC,WAAQC,IACnCA,EAAUC,aAAYN,OACE,SAAnBA,EAASO,OAAoBP,EAASQ,MAAO,OAC1CC,EAAWC,EAAoBV,GAErCA,EAASO,MAAQE,EAAW,WAAa,aAEnCE,EAAYP,UAAOO,UAAU,CAClCA,UAAWC,EAAcC,OAAOb,MAG7BS,EACHT,EAASc,OAAOA,OAAOC,YAAYJ,GAEnCX,EAASe,YAAYJ,UAItBK,YAAYlB,EAAKE,UAEpBE,EAAmBW,OAAOV,GACzB,MAAOc,eACRnB,EAAKoB,KAAKnB,EAAS,8BAA6BD,EAAKE,iBAItB,IAArBE,GAIPA,IAAqBJ,EAAKE,WAI1BP,EACHK,EAAKqB,YAAY,CAAEnB,SAAUE,IAE7BJ,EAAKsB,OAAO,CAAEpB,SAAUE,QAM5BZ,EAAQ+B,SAAU,EAGlB,MAAM7B,EAAiB,CAAEG,UAAU,GAG7BiB,EAAuCL,GAAUe,mBAAmBf,GAAOgB,QAAQ,OAAQ,KAAKA,QAAQ,OAAQ,KAAKA,QAAQ,OAAQ,KAAKA,QAAQ,OAAQ,KAAKA,QAAQ,cAAe,QAGtLb,EAAuBV,kBAA+C,qBAAlCA,EAASc,oBAAQA,iBAAQU,OAAsD,SAAjCxB,EAASc,OAAOA,OAAOP"}