specificities-overlap.js 806 B

12345678910111213141516171819202122232425262728293031323334
  1. var specificity = require('./specificity');
  2. function specificitiesOverlap(selector1, selector2, cache) {
  3. var specificity1;
  4. var specificity2;
  5. var i, l;
  6. var j, m;
  7. for (i = 0, l = selector1.length; i < l; i++) {
  8. specificity1 = findSpecificity(selector1[i][1], cache);
  9. for (j = 0, m = selector2.length; j < m; j++) {
  10. specificity2 = findSpecificity(selector2[j][1], cache);
  11. if (specificity1[0] === specificity2[0] && specificity1[1] === specificity2[1] && specificity1[2] === specificity2[2]) {
  12. return true;
  13. }
  14. }
  15. }
  16. return false;
  17. }
  18. function findSpecificity(selector, cache) {
  19. var value;
  20. if (!(selector in cache)) {
  21. cache[selector] = value = specificity(selector);
  22. }
  23. return value || cache[selector];
  24. }
  25. module.exports = specificitiesOverlap;