Selector.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5. // Generated by CoffeeScript 2.5.1
  6. var CSSSelect, Selector;
  7. CSSSelect = require('css-select');
  8. module.exports = Selector = function () {
  9. var self;
  10. var Selector = /*#__PURE__*/function () {
  11. function Selector(text1) {
  12. _classCallCheck(this, Selector);
  13. this.text = text1;
  14. this._fn = CSSSelect.compile(this.text);
  15. this.priority = self.calculatePriority(this.text);
  16. }
  17. _createClass(Selector, [{
  18. key: "matches",
  19. value: function matches(elem) {
  20. return CSSSelect.is(elem, this._fn);
  21. } // This stupid piece of code is supposed to calculate
  22. // selector priority, somehow according to
  23. // http://www.w3.org/wiki/CSS/Training/Priority_level_of_selector
  24. }], [{
  25. key: "calculatePriority",
  26. value: function calculatePriority(text) {
  27. var n, priotrity;
  28. priotrity = 0;
  29. if (n = text.match(/[\#]{1}/g)) {
  30. priotrity += 100 * n.length;
  31. }
  32. if (n = text.match(/[a-zA-Z]+/g)) {
  33. priotrity += 2 * n.length;
  34. }
  35. if (n = text.match(/\*/g)) {
  36. priotrity += 1 * n.length;
  37. }
  38. return priotrity;
  39. }
  40. }]);
  41. return Selector;
  42. }();
  43. ;
  44. self = Selector;
  45. return Selector;
  46. }.call(void 0);