postcss-pseudo-class-any-link
Advanced tools
Comparing version 5.0.0 to 6.0.0
# Changes to PostCSS Pseudo Class Any Link | ||
### 6.0.0 (September 17, 2018) | ||
- Updated: Support for PostCSS v7+ | ||
- Updated: Support for Node v6+ | ||
- Updated: PostCSS Selector Parser 5.0.0-rc.3 (major) | ||
### 5.0.0 (May 7, 2018) | ||
@@ -4,0 +10,0 @@ |
102
index.cjs.js
@@ -8,67 +8,59 @@ 'use strict'; | ||
var anyAnyLinkMatch = /:any-link/; | ||
const anyAnyLinkMatch = /:any-link/; | ||
var index = postcss.plugin('postcss-pseudo-class-any-link', opts => { | ||
const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true; | ||
return root => { | ||
// walk each matching rule | ||
root.walkRules(anyAnyLinkMatch, rule => { | ||
const rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector; // workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556 | ||
var index = postcss.plugin('postcss-pseudo-class-any-link', function (opts) { | ||
var preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true; | ||
if (rawSelector[rawSelector.length - 1] !== ':') { | ||
// update the selector | ||
const updatedSelector = parser(selectors => { | ||
// cache variables | ||
let node; | ||
let nodeIndex; | ||
let selector; | ||
let selectorLink; | ||
let selectorVisited; // cache the selector index | ||
return function (root) { | ||
// walk each matching rule | ||
root.walkRules(anyAnyLinkMatch, function (rule) { | ||
var rawSelector = rule.raws.selector && rule.raws.selector.raw || rule.selector; | ||
let selectorIndex = -1; // for each selector | ||
// workaround for https://github.com/postcss/postcss-selector-parser/issues/28#issuecomment-171910556 | ||
if (rawSelector[rawSelector.length - 1] !== ':') { | ||
// update the selector | ||
var updatedSelector = parser(function (selectors) { | ||
// cache variables | ||
var node = void 0; | ||
var nodeIndex = void 0; | ||
var selector = void 0; | ||
var selectorLink = void 0; | ||
var selectorVisited = void 0; | ||
while (selector = selectors.nodes[++selectorIndex]) { | ||
// reset the node index | ||
nodeIndex = -1; // for each node | ||
// cache the selector index | ||
var selectorIndex = -1; | ||
while (node = selector.nodes[++nodeIndex]) { | ||
// if the node value matches the any-link value | ||
if (node.value === ':any-link') { | ||
// clone the selector | ||
selectorLink = selector.clone(); | ||
selectorVisited = selector.clone(); // update the matching clone values | ||
// for each selector | ||
while (selector = selectors.nodes[++selectorIndex]) { | ||
// reset the node index | ||
nodeIndex = -1; | ||
selectorLink.nodes[nodeIndex].value = ':link'; | ||
selectorVisited.nodes[nodeIndex].value = ':visited'; // replace the selector with the clones and roll back the selector index | ||
// for each node | ||
while (node = selector.nodes[++nodeIndex]) { | ||
// if the node value matches the any-link value | ||
if (node.value === ':any-link') { | ||
// clone the selector | ||
selectorLink = selector.clone(); | ||
selectorVisited = selector.clone(); | ||
selectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited); // stop updating the selector | ||
// update the matching clone values | ||
selectorLink.nodes[nodeIndex].value = ':link'; | ||
selectorVisited.nodes[nodeIndex].value = ':visited'; | ||
break; | ||
} | ||
} | ||
} | ||
}).processSync(rawSelector); | ||
// replace the selector with the clones and roll back the selector index | ||
selectors.nodes.splice(selectorIndex--, 1, selectorLink, selectorVisited); | ||
// stop updating the selector | ||
break; | ||
} | ||
} | ||
} | ||
}).processSync(rawSelector); | ||
if (updatedSelector !== rawSelector) { | ||
if (preserve) { | ||
rule.cloneBefore({ | ||
selector: updatedSelector | ||
}); | ||
} else { | ||
rule.selector = updatedSelector; | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
if (updatedSelector !== rawSelector) { | ||
if (preserve) { | ||
rule.cloneBefore({ | ||
selector: updatedSelector | ||
}); | ||
} else { | ||
rule.selector = updatedSelector; | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
}); | ||
module.exports = index; | ||
//# sourceMappingURL=index.cjs.js.map |
{ | ||
"name": "postcss-pseudo-class-any-link", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Use the :any-link pseudo-class in CSS", | ||
@@ -11,6 +11,8 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"main": "index.cjs.js", | ||
"module": "index.es.js", | ||
"module": "index.es.mjs", | ||
"files": [ | ||
"index.cjs.js", | ||
"index.es.js" | ||
"index.cjs.js.map", | ||
"index.es.mjs", | ||
"index.es.mjs.map" | ||
], | ||
@@ -26,18 +28,18 @@ "scripts": { | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=6.0.0" | ||
}, | ||
"dependencies": { | ||
"postcss": "^6.0.22", | ||
"postcss-selector-parser": "^4.0.0" | ||
"postcss": "^7.0.2", | ||
"postcss-selector-parser": "^5.0.0-rc.3" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^8.2.3", | ||
"babel-preset-env": "^1.6.1", | ||
"eslint": "^4.19.1", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"babel-eslint": "^9.0.0", | ||
"eslint": "^5.6.0", | ||
"eslint-config-dev": "^2.0.0", | ||
"postcss-tape": "^2.2.0", | ||
"pre-commit": "^1.2.2", | ||
"rollup": "^0.58.2", | ||
"rollup-plugin-babel": "^3.0.4" | ||
"rollup": "^0.66.0", | ||
"rollup-plugin-babel": "^4.0.1" | ||
}, | ||
@@ -44,0 +46,0 @@ "eslintConfig": { |
115
README.md
@@ -6,3 +6,2 @@ # PostCSS Pseudo Class Any Link [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss] | ||
[![Build Status][cli-img]][cli-url] | ||
[![Windows Build Status][win-img]][win-url] | ||
[![Support Chat][git-img]][git-url] | ||
@@ -37,3 +36,3 @@ | ||
Add [PostCSS Pseudo Class Any Link] to your build tool: | ||
Add [PostCSS Pseudo Class Any Link] to your project: | ||
@@ -44,117 +43,27 @@ ```bash | ||
#### Node | ||
Use [PostCSS Pseudo Class Any Link] to process your CSS: | ||
```js | ||
import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link'; | ||
const postcssPseudoClassAnyLink = require('postcss-pseudo-class-any-link'); | ||
postcssPseudoClassAnyLink.process(YOUR_CSS, /* processOptions */, /* pluginOptions */); | ||
postcssPseudoClassAnyLink.process(YOUR_CSS /*, processOptions, pluginOptions */); | ||
``` | ||
#### PostCSS | ||
Or use it as a [PostCSS] plugin: | ||
Add [PostCSS] to your build tool: | ||
```bash | ||
npm install postcss --save-dev | ||
``` | ||
Use [PostCSS Pseudo Class Any Link] as a plugin: | ||
```js | ||
import postcss from 'gulp-postcss'; | ||
import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link'; | ||
const postcss = require('postcss'); | ||
const postcssPseudoClassAnyLink = require('postcss-pseudo-class-any-link'); | ||
postcss([ | ||
postcssPseudoClassAnyLink(/* pluginOptions */) | ||
]).process(YOUR_CSS); | ||
]).process(YOUR_CSS /*, processOptions */); | ||
``` | ||
#### Webpack | ||
[PostCSS Pseudo Class Any Link] runs in all Node environments, with special | ||
instructions for: | ||
Add [PostCSS Loader] to your build tool: | ||
| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) | | ||
| --- | --- | --- | --- | --- | --- | | ||
```bash | ||
npm install postcss-loader --save-dev | ||
``` | ||
Use [PostCSS Pseudo Class Any Link] in your Webpack configuration: | ||
```js | ||
import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link'; | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
'style-loader', | ||
{ loader: 'css-loader', options: { importLoaders: 1 } }, | ||
{ loader: 'postcss-loader', options: { | ||
ident: 'postcss', | ||
plugins: () => [ | ||
postcssPseudoClassAnyLink(/* pluginOptions */) | ||
] | ||
} } | ||
] | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
#### Gulp | ||
Add [Gulp PostCSS] to your build tool: | ||
```bash | ||
npm install gulp-postcss --save-dev | ||
``` | ||
Use [PostCSS Pseudo Class Any Link] in your Gulpfile: | ||
```js | ||
import postcss from 'gulp-postcss'; | ||
import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link'; | ||
gulp.task('css', () => gulp.src('./src/*.css').pipe( | ||
postcss([ | ||
postcssPseudoClassAnyLink(/* pluginOptions */) | ||
]) | ||
).pipe( | ||
gulp.dest('.') | ||
)); | ||
``` | ||
#### Grunt | ||
Add [Grunt PostCSS] to your build tool: | ||
```bash | ||
npm install grunt-postcss --save-dev | ||
``` | ||
Use [PostCSS Pseudo Class Any Link] in your Gruntfile: | ||
```js | ||
import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link'; | ||
grunt.loadNpmTasks('grunt-postcss'); | ||
grunt.initConfig({ | ||
postcss: { | ||
options: { | ||
use: [ | ||
postcssPseudoClassAnyLink(/* pluginOptions */) | ||
] | ||
}, | ||
dist: { | ||
src: '*.css' | ||
} | ||
} | ||
}); | ||
``` | ||
## Options | ||
@@ -191,4 +100,2 @@ | ||
[npm-url]: https://www.npmjs.com/package/postcss-pseudo-class-any-link | ||
[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-pseudo-class-any-link.svg | ||
[win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-pseudo-class-any-link | ||
@@ -195,0 +102,0 @@ [Gulp PostCSS]: https://github.com/postcss/gulp-postcss |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25224
8
104
104
+ Addedcssesc@2.0.0(transitive)
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedpostcss-selector-parser@5.0.0(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcssesc@1.0.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedpostcss@6.0.23(transitive)
- Removedpostcss-selector-parser@4.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedpostcss@^7.0.2