1 | ;
|
2 |
|
3 | /**
|
4 | * Module dependencies.
|
5 | */
|
6 |
|
7 | var specificity = require('specificity');
|
8 |
|
9 | /**
|
10 | * Returns specificity based on selector text and tokens.
|
11 | *
|
12 | * @param {String} selector
|
13 | * @param {Array} tokens
|
14 | * @api private.
|
15 | */
|
16 |
|
17 | function getSpecificity(text) {
|
18 | var spec = specificity.calculate(text);
|
19 |
|
20 | return spec[0].specificity.split(',');
|
21 | }
|
22 |
|
23 | /**
|
24 | * CSS selector constructor.
|
25 | *
|
26 | * @param {String} selector text
|
27 | * @param {Array} optionally, precalculated specificity
|
28 | * @api public
|
29 | */
|
30 |
|
31 | module.exports = function (text, spec) {
|
32 | var _spec = spec,
|
33 |
|
34 | /**
|
35 | * Lazy specificity getter
|
36 | *
|
37 | * @api public
|
38 | */
|
39 |
|
40 | _specificity = function () {
|
41 | if (!spec) {
|
42 | _spec = getSpecificity(text);
|
43 | }
|
44 | return _spec;
|
45 | };
|
46 |
|
47 | return {
|
48 | spec: _spec,
|
49 |
|
50 | specificity: _specificity
|
51 | };
|
52 | };
|