postcss-focus
Advanced tools
Comparing version 3.0.0 to 4.0.0
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 4.0 | ||
* Use PostCSS 7. | ||
* Remove Node.js 4 support. | ||
## 3.0 | ||
@@ -5,0 +9,0 @@ * Do not process if there is a `:focus` selector already (by Vitalii Rizo). |
46
index.js
@@ -1,28 +0,28 @@ | ||
var postcss = require('postcss'); | ||
var postcss = require('postcss') | ||
function hasAlready(parent, selector) { | ||
return parent.nodes.some(function (i) { | ||
return i.type === 'rule' && i.selectors.indexOf(selector) !== -1; | ||
}); | ||
function hasAlready (parent, selector) { | ||
return parent.nodes.some(function (i) { | ||
return i.type === 'rule' && i.selectors.indexOf(selector) !== -1 | ||
}) | ||
} | ||
module.exports = postcss.plugin('postcss-focus', function () { | ||
return function (css) { | ||
css.walkRules(function (rule) { | ||
if ( rule.selector.indexOf(':hover') !== -1 ) { | ||
var focuses = []; | ||
rule.selectors.forEach(function (selector) { | ||
if ( selector.indexOf(':hover') !== -1 ) { | ||
var replaced = selector.replace(/:hover/g, ':focus'); | ||
if ( !hasAlready(rule.parent, replaced) ) { | ||
focuses.push(replaced); | ||
} | ||
} | ||
}); | ||
if ( focuses.length ) { | ||
rule.selectors = rule.selectors.concat(focuses); | ||
} | ||
return function (css) { | ||
css.walkRules(function (rule) { | ||
if (rule.selector.indexOf(':hover') !== -1) { | ||
var focuses = [] | ||
rule.selectors.forEach(function (selector) { | ||
if (selector.indexOf(':hover') !== -1) { | ||
var replaced = selector.replace(/:hover/g, ':focus') | ||
if (!hasAlready(rule.parent, replaced)) { | ||
focuses.push(replaced) | ||
} | ||
}); | ||
}; | ||
}); | ||
} | ||
}) | ||
if (focuses.length) { | ||
rule.selectors = rule.selectors.concat(focuses) | ||
} | ||
} | ||
}) | ||
} | ||
}) |
{ | ||
"name": "postcss-focus", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "PostCSS plugin to add :focus selector to every :hover for keyboard accessibility", | ||
@@ -23,34 +23,4 @@ "keywords": [ | ||
"dependencies": { | ||
"postcss": "^6.0.13" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.8.0", | ||
"eslint-config-postcss": "^2.0.2", | ||
"jest": "^21.2.1", | ||
"lint-staged": "^4.2.3", | ||
"pre-commit": "^1.2.2" | ||
}, | ||
"scripts": { | ||
"lint-staged": "lint-staged", | ||
"test": "jest --coverage && eslint *.js" | ||
}, | ||
"jest": { | ||
"coverageThreshold": { | ||
"global": { | ||
"statements": 100 | ||
} | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "eslint-config-postcss/es5", | ||
"env": { | ||
"jest": true | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": "eslint" | ||
}, | ||
"pre-commit": [ | ||
"lint-staged" | ||
] | ||
"postcss": "^7.0.2" | ||
} | ||
} |
0
4093
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedpostcss@6.0.23(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedpostcss@^7.0.2