From c06f7ee0a40255214c477e13d9b956a7e07c2900 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 14 Oct 2023 15:05:55 +0800 Subject: postcss,(plugins): nanocss, postcss-preset-env --- .../stylehacks/src/plugins/htmlFirstChild.js | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 node_modules/stylehacks/src/plugins/htmlFirstChild.js (limited to 'node_modules/stylehacks/src/plugins/htmlFirstChild.js') diff --git a/node_modules/stylehacks/src/plugins/htmlFirstChild.js b/node_modules/stylehacks/src/plugins/htmlFirstChild.js new file mode 100644 index 00000000..f772786b --- /dev/null +++ b/node_modules/stylehacks/src/plugins/htmlFirstChild.js @@ -0,0 +1,50 @@ +'use strict'; +const parser = require('postcss-selector-parser'); +const exists = require('../exists'); +const isMixin = require('../isMixin'); +const BasePlugin = require('../plugin'); +const { OP_9 } = require('../dictionary/browsers'); +const { SELECTOR } = require('../dictionary/identifiers'); +const { RULE } = require('../dictionary/postcss'); +const { HTML } = require('../dictionary/tags'); + +module.exports = class HtmlFirstChild extends BasePlugin { + /** @param {import('postcss').Result} result */ + constructor(result) { + super([OP_9], [RULE], result); + } + + /** + * @param {import('postcss').Rule} rule + * @return {void} + */ + detect(rule) { + if (isMixin(rule)) { + return; + } + + parser(this.analyse(rule)).processSync(rule.selector); + } + + /** + * @param {import('postcss').Rule} rule + * @return {parser.SyncProcessor} + */ + analyse(rule) { + return (selectors) => { + selectors.each((selector) => { + if ( + exists(selector, 0, HTML) && + exists(selector, 1, ':first-child') && + exists(selector, 2, ' ') && + selector.at(3) + ) { + this.push(rule, { + identifier: SELECTOR, + hack: selector.toString(), + }); + } + }); + }; + } +}; -- cgit v1.2.3