{"_id":"postcss-custom-selector","_rev":"5-b98c7b9a91c3f2bc8e9905a0cdb04018","name":"postcss-custom-selector","description":"PostCSS plugin","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"postcss-custom-selector","version":"1.0.0","description":"PostCSS plugin","keywords":["css","postcss","postcss-plugins","selector","custom selector"],"author":{"name":"yisi"},"license":"MIT","repository":{"type":"git","url":"https://github.com/postcss/postcss-custom-selector.git"},"files":["CHANGELOG.md","LICENSE","index.js"],"devDependencies":{"postcss":"^3.0.0","tape":"^3.0.0"},"scripts":{"test":"tape test"},"gitHead":"7cf1085d91d8a304f0b3d5554c74bf416df9e779","bugs":{"url":"https://github.com/postcss/postcss-custom-selector/issues"},"homepage":"https://github.com/postcss/postcss-custom-selector","_id":"postcss-custom-selector@1.0.0","_shasum":"a96ef0c7fefa2a11ea9be7a4dd3b97b0fce4a3a0","_from":".","_npmVersion":"2.1.10","_nodeVersion":"0.10.26","_npmUser":{"name":"yisi","email":"yiorsi@gmail.com"},"maintainers":[{"name":"yisi","email":"yiorsi@gmail.com"}],"dist":{"shasum":"a96ef0c7fefa2a11ea9be7a4dd3b97b0fce4a3a0","tarball":"https://registry.npmjs.org/postcss-custom-selector/-/postcss-custom-selector-1.0.0.tgz","integrity":"sha512-ZYQpsyk4LiZ7ZrNdyyjCZEh3CBPeLY42OfO7BPSKGuUaXHH8grJyW44RLQxmS4EG4oruWrJk9NTmrQ6FBgcVLA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCM5jASKr6pFPz585SAzMnQNwG7wMDFlFisQG/v5Wr/wAIhAMs4Mv2zvETNSbeVgBZelAKRALAv6VvXtYVxJnGzoboq"}]},"deprecated":"Please use npm install postcss-custom-selectors instead (with an S at the end)."}},"readme":"# PostCSS Custom Selector [![Build Status](https://travis-ci.org/postcss/postcss-custom-selector.png)](https://travis-ci.org/postcss/postcss-custom-selector)\n\n> [PostCSS](https://github.com/postcss/postcss) 实现 [W3C CSS Extensions(Custom Selectors)](http://dev.w3.org/csswg/css-extensions/#custom-selectors) 的插件。\n\n\n\n## 安装(暂未发布)\n\n    $ npm install postcss-custom-selector\n\n## 快速开始\n\n```js\n// dependencies\nvar fs = require('fs')\nvar postcss = require('postcss')\nvar selector = require('postcss-custom-selector')\n\n// css to be processed\nvar css = fs.readFileSync('input.css', 'utf8')\n\n// process css using postcss-custom-selector\nvar output = postcss()\n  .use(selector())\n  .process(css)\n  .css\n  \nconsole.log('\\n\\n ====>Output CSS:\\n',output)  \n```\n\n或者：\n\n```js\nvar output = postcss(selector())\n  .process(css)\n  .css\n```\n\ninput.css：\n\n```css\n@custom-selector --heading h1, h2, h3, h4, h5, h6;\n\narticle --heading + p{ \n  margin-top: 0;\n}\n```\n\n你将得到：\n\n```css\narticle h1 + p, article h2 + p, article h3 + p, article h4 + p, article h5 + p, article h6 + p{\n  margin-top: 0;\n}\n```\n\n## CSS 语法\n\nA custom selector is defined with the `@custom-selector` rule:\n\n    @custom-selector = @custom-selector <extension-name> <selector>;\n\nThis defines a custom selector which is written as a pseudo-class with the given `<extension-name>`, and represents a `:matches()` selector using the provided `<selector>` as its argument.\n\n\nFor example, if an author wanted to easily refer to all heading elements in their HTML document, they could create an alias:\n\n```css\n@custom-selector :--heading h1, h2, h3, h4, h5, h6;\n\n:--heading { /* styles for all headings */ }\n:--heading + p { /* more styles */ }\n/* etc */\n```\n\n## 如何使用\n\n### 伪元素/伪类\n\n你可以使用 \n\n* `:` 自定义一个伪类。\n* `::`自定义一个伪元素。\n\n例如，模拟一个 :any-link 选择器：\n\ninput.css:\n\n```css\n@custom-selector :--any-link :link, :visited;\n\na:--any-link {\n  color: blue;\n}\n```\n\noutput:\n\n```css\na:link, a:visited {\n  color: blue;\n}\n```\n### 多个选择器\n\n`@custom-selector` 类似 CSS [`:matches()`](http://dev.w3.org/csswg/selectors-4/#matches) 选择器，但是目前**不支持**在同一个选择器中调用多个自定义选择器，例如：\n\n```css\n@custom-selector --heading h1, h2, h3, h4, h5, h6;\n@custom-selector :--any-link :link, :visited;\n\n.demo --heading, a:--any-link { \n  font-size: 32px;\n}\n```\n将会输出错误的 CSS 代码。\n\n### Grunt\n\n```js\ngrunt.initConfig({\n  postcss: {\n    options: {\n      processors: [require('postcss-custom-selector').postcss]\n    },\n    dist: {\n      src: 'css/*.css'\n    }\n  }\n});\n\ngrunt.loadNpmTasks('grunt-postcss');\n```\n\n### Gulp\n\n```js\nvar gulp = require('gulp');\nvar postcss = require('gulp-postcss');\n\ngulp.task('css', function() {\n  return gulp.src('./src/*.css')\n    .pipe(postcss([require('postcss-custom-selector')]))\n    .pipe(gulp.dest('./dest'));\n});\n```\n\n\n\n### 选项\n\n**`extensions`** (默认: `{}`)\n\n该选项允许你自定义一个对象来设置 `<extension-name>`（选择器别名）和 `<selector>`，这些定义将覆盖 CSS 中相同别名的 `@custom-selector`。\n\n```js\nvar options = {\n  extensions: {\n    ':--any' : 'section, article, aside, nav'\n  }\n}\n\nvar output = postcss(selector(options))\n  .process(css)\n  .css;\n```\n\ninput.css\n\n```css\n@custom-selector :--any .foo, .bar; /* 不会生效 */\n:--any h1 {\n  margin-top: 16px;\n}\n```\n\noutput:\n\n```css\nsection h1, article h1, aside h1, nav h1 {\n  margin-top: 16px;\n}\n```\n\n\n## 贡献\n\n* 安装相关依赖模块\n* 尊重编码风格（安装）\n* 运行测试\n\n```\n$ git clone https://github.com/postcss/postcss-custom-selector.git\n$ git checkout -b patch\n$ npm install\n$ npm test\n```\n\n## [Changelog](CHANGELOG.md)\n\n## [License](LICENSE)\n","maintainers":[{"name":"yisi","email":"yiorsi@gmail.com"}],"time":{"modified":"2022-06-24T09:46:47.076Z","created":"2014-12-04T12:16:30.636Z","1.0.0":"2014-12-04T12:16:30.636Z"},"homepage":"https://github.com/postcss/postcss-custom-selector","keywords":["css","postcss","postcss-plugins","selector","custom selector"],"repository":{"type":"git","url":"https://github.com/postcss/postcss-custom-selector.git"},"author":{"name":"yisi"},"bugs":{"url":"https://github.com/postcss/postcss-custom-selector/issues"},"license":"MIT","readmeFilename":"README.md"}