{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import parser from 'postcss-selector-parser';\n\nconst anyAnyLinkMatch = /:any-link/;\n\n/**\n * @param {{preserve?: boolean}} opts\n * @returns {import('postcss').Plugin}\n */\nfunction creator(opts) {\n\tconst preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;\n\n\treturn {\n\t\tpostcssPlugin: 'postcss-pseudo-class-any-link',\n\t\tRule(rule, { result }) {\n\t\t\tif (!anyAnyLinkMatch.test(rule.selector)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector;\n\n\t\t\t// workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556\n\t\t\tif (rawSelector[rawSelector.length - 1] === ':') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet updatedSelector;\n\n\t\t\ttry {\n\t\t\t\t// update the selector\n\t\t\t\tupdatedSelector = parser(selectors => {\n\t\t\t\t\t// cache variables\n\t\t\t\t\tlet node;\n\t\t\t\t\tlet nodeIndex;\n\t\t\t\t\tlet selector;\n\t\t\t\t\tlet selectorLink;\n\t\t\t\t\tlet selectorVisited;\n\n\t\t\t\t\t// cache the selector index\n\t\t\t\t\tlet selectorIndex = -1;\n\n\t\t\t\t\t// for each selector\n\t\t\t\t\tselector = selectors.nodes[++selectorIndex];\n\t\t\t\t\twhile (selector) {\n\t\t\t\t\t\t// reset the node index\n\t\t\t\t\t\tnodeIndex = -1;\n\n\t\t\t\t\t\t// for each node\n\t\t\t\t\t\tnode = selector.nodes[++nodeIndex];\n\t\t\t\t\t\twhile (node) {\n\t\t\t\t\t\t\t// if the node value matches the any-link value\n\t\t\t\t\t\t\tif (node.value !== ':any-link' || node.type !== 'pseudo' || (node.nodes && node.nodes.length)) {\n\t\t\t\t\t\t\t\tnode = selector.nodes[++nodeIndex];\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// clone the selector\n\t\t\t\t\t\t\tselectorLink = selector.clone();\n\t\t\t\t\t\t\tselectorVisited = selector.clone();\n\n\t\t\t\t\t\t\t// update the matching clone values\n\t\t\t\t\t\t\tselectorLink.nodes[nodeIndex].value = ':link';\n\t\t\t\t\t\t\tselectorVisited.nodes[nodeIndex].value = ':visited';\n\n\t\t\t\t\t\t\t// replace the selector with the clones and roll back the selector index\n\t\t\t\t\t\t\tselectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited);\n\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tselector = selectors.nodes[++selectorIndex];\n\t\t\t\t\t}\n\t\t\t\t}).processSync(rawSelector);\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 updatedSelector === 'undefined') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (updatedSelector === rawSelector) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (preserve) {\n\t\t\t\trule.cloneBefore({\n\t\t\t\t\tselector: updatedSelector,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\trule.selector = updatedSelector;\n\t\t\t}\n\t\t},\n\t};\n}\n\ncreator.postcss = true;\n\nexport default creator;\n"],"names":["anyAnyLinkMatch","creator","opts","preserve","Object","Boolean","postcssPlugin","Rule","rule","result","test","selector","rawSelector","raws","raw","length","updatedSelector","parser","selectors","node","nodeIndex","selectorLink","selectorVisited","selectorIndex","nodes","value","type","clone","splice","processSync","_","warn","cloneBefore","postcss"],"mappings":"iIAEA,MAAMA,EAAkB,YAMxB,SAASC,EAAQC,SACVC,IAAW,aAAcC,OAAOF,KAAQG,QAAQH,EAAKC,gBAEpD,CACNG,cAAe,gCACfC,KAAKC,GAAMC,OAAEA,QACPT,EAAgBU,KAAKF,EAAKG,uBAIzBC,EAAcJ,EAAKK,KAAKF,UAAYH,EAAKK,KAAKF,SAASG,KAAON,EAAKG,YAG7B,MAAxCC,EAAYA,EAAYG,OAAS,cAIjCC,MAIHA,EAAkBC,WAAOC,QAEpBC,EACAC,EACAT,EACAU,EACAC,EAGAC,GAAiB,MAGrBZ,EAAWO,EAAUM,QAAQD,GACtBZ,GAAU,KAEhBS,GAAa,EAGbD,EAAOR,EAASa,QAAQJ,GACjBD,GAAM,MAEO,cAAfA,EAAKM,OAAuC,WAAdN,EAAKO,MAAsBP,EAAKK,OAASL,EAAKK,MAAMT,SAMtFM,EAAeV,EAASgB,QACxBL,EAAkBX,EAASgB,QAG3BN,EAAaG,MAAMJ,GAAWK,MAAQ,QACtCH,EAAgBE,MAAMJ,GAAWK,MAAQ,WAGzCP,EAAUM,MAAMI,OAAOL,IAAiB,EAAGF,EAAcC,SAbxDH,EAAOR,EAASa,QAAQJ,GAkB1BT,EAAWO,EAAUM,QAAQD,OAE5BM,YAAYjB,GACd,MAAOkB,eACRtB,EAAKuB,KAAKtB,EAAS,8BAA6BD,EAAKG,iBAIvB,IAApBK,GAIPA,IAAoBJ,IAIpBT,EACHK,EAAKwB,YAAY,CAChBrB,SAAUK,IAGXR,EAAKG,SAAWK,KAMpBf,EAAQgC,SAAU"}