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