You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.2 KiB

4 years ago
{"version":3,"file":"postcss.js","sources":["src/postcss.js"],"sourcesContent":["import parser from 'postcss-selector-parser';\nimport postcss from 'postcss';\n\nconst selectorRegExp = /:has/;\n\nexport default postcss.plugin('css-has-pseudo', opts => {\n\tconst preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);\n\n\treturn root => {\n\t\troot.walkRules(selectorRegExp, rule => {\n\t\t\tconst modifiedSelector = parser(selectors => {\n\t\t\t\tselectors.walkPseudos(selector => {\n\t\t\t\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\t\t\t\tconst isNotHas = checkIfParentIsNot(selector);\n\t\t\t\t\t\tselector.value = isNotHas ? ':not-has' : ':has';\n\n\t\t\t\t\t\tconst attribute = parser.attribute({\n\t\t\t\t\t\t\tattribute: encodeURIComponent(String(selector))\n\t\t\t\t\t\t\t.replace(/%3A/g, ':')\n\t\t\t\t\t\t\t.replace(/%5B/g, '[')\n\t\t\t\t\t\t\t.replace(/%5D/g, ']')\n\t\t\t\t\t\t\t.replace(/%2C/g, ',')\n\t\t\t\t\t\t\t.replace(/[():%\\[\\],]/g, '\\\\$&')\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (isNotHas) {\n\t\t\t\t\t\t\tselector.parent.parent.replaceWith(attribute);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tselector.replaceWith(attribute);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}).processSync(rule.selector);\n\n\t\t\tconst clone = rule.clone({ selector: modifiedSelector });\n\n\t\t\tif (preserve) {\n\t\t\t\trule.before(clone);\n\t\t\t} else {\n\t\t\t\trule.replaceWith(clone);\n\t\t\t}\n\t\t});\n\t};\n});\n\nfunction checkIfParentIsNot(selector) {\n\treturn Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';\n}\n"],"names":["selectorRegExp","postcss","plugin","opts","preserve","Boolean","Object","root","walkRules","rule","modifiedSelector","parser","selectors","walkPseudos","selector","value","nodes","isNotHas","checkIfParentIsNot","attribute","encodeURIComponent","String","replace","parent","replaceWith","processSync","clone","before","type"],"mappings":";;;;;;;AAGA,MAAMA,cAAc,GAAG,MAAvB;AAEA,gBAAeC,OAAO,CAACC,MAAR,CAAe,gBAAf,EAAiCC,IAAI,IAAI;QACjDC,QAAQ,GAAGC,OAAO,CAAC,cAAcC,MAAM,CAACH,IAAD,CAApB,GAA6BA,IAAI,CAACC,QAAlC,GAA6C,IAA9C,CAAxB;SAEOG,IAAI,IAAI;IACdA,IAAI,CAACC,SAAL,CAAeR,cAAf,EAA+BS,IAAI,IAAI;YAChCC,gBAAgB,GAAGC,MAAM,CAACC,SAAS,IAAI;QAC5CA,SAAS,CAACC,WAAV,CAAsBC,QAAQ,IAAI;cAC7BA,QAAQ,CAACC,KAAT,KAAmB,MAAnB,IAA6BD,QAAQ,CAACE,KAA1C,EAAiD;kBAC1CC,QAAQ,GAAGC,kBAAkB,CAACJ,QAAD,CAAnC;YACAA,QAAQ,CAACC,KAAT,GAAiBE,QAAQ,GAAG,UAAH,GAAgB,MAAzC;kBAEME,SAAS,GAAGR,MAAM,CAACQ,SAAP,CAAiB;cAClCA,SAAS,EAAEC,kBAAkB,CAACC,MAAM,CAACP,QAAD,CAAP,CAAlB,CACVQ,OADU,CACF,MADE,EACM,GADN,EAEVA,OAFU,CAEF,MAFE,EAEM,GAFN,EAGVA,OAHU,CAGF,MAHE,EAGM,GAHN,EAIVA,OAJU,CAIF,MAJE,EAIM,GAJN,EAKVA,OALU,CAKF,cALE,EAKc,MALd;aADM,CAAlB;;gBASIL,QAAJ,EAAc;cACbH,QAAQ,CAACS,MAAT,CAAgBA,MAAhB,CAAuBC,WAAvB,CAAmCL,SAAnC;aADD,MAEO;cACNL,QAAQ,CAACU,WAAT,CAAqBL,SAArB;;;SAjBH;OAD8B,CAAN,CAsBtBM,WAtBsB,CAsB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