1 | "use strict";
|
---|
2 |
|
---|
3 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
---|
4 |
|
---|
5 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
6 |
|
---|
7 | 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); } }
|
---|
8 |
|
---|
9 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
---|
10 |
|
---|
11 | // Generated by CoffeeScript 2.5.1
|
---|
12 | var Rule, StyleSheet;
|
---|
13 | Rule = require('./Rule');
|
---|
14 |
|
---|
15 | module.exports = StyleSheet = function () {
|
---|
16 | var self;
|
---|
17 |
|
---|
18 | var StyleSheet = /*#__PURE__*/function () {
|
---|
19 | function StyleSheet() {
|
---|
20 | _classCallCheck(this, StyleSheet);
|
---|
21 |
|
---|
22 | this._rulesBySelector = {};
|
---|
23 | }
|
---|
24 |
|
---|
25 | _createClass(StyleSheet, [{
|
---|
26 | key: "setRule",
|
---|
27 | value: function setRule(selector, styles) {
|
---|
28 | var key, val;
|
---|
29 |
|
---|
30 | if (typeof selector === 'string') {
|
---|
31 | this._setRule(selector, styles);
|
---|
32 | } else if (_typeof(selector) === 'object') {
|
---|
33 | for (key in selector) {
|
---|
34 | val = selector[key];
|
---|
35 |
|
---|
36 | this._setRule(key, val);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | return this;
|
---|
41 | }
|
---|
42 | }, {
|
---|
43 | key: "_setRule",
|
---|
44 | value: function _setRule(s, styles) {
|
---|
45 | var i, len, ref, selector;
|
---|
46 | ref = self.splitSelectors(s);
|
---|
47 |
|
---|
48 | for (i = 0, len = ref.length; i < len; i++) {
|
---|
49 | selector = ref[i];
|
---|
50 |
|
---|
51 | this._setSingleRule(selector, styles);
|
---|
52 | }
|
---|
53 |
|
---|
54 | return this;
|
---|
55 | }
|
---|
56 | }, {
|
---|
57 | key: "_setSingleRule",
|
---|
58 | value: function _setSingleRule(s, styles) {
|
---|
59 | var rule, selector;
|
---|
60 | selector = self.normalizeSelector(s);
|
---|
61 |
|
---|
62 | if (!(rule = this._rulesBySelector[selector])) {
|
---|
63 | rule = new Rule(selector);
|
---|
64 | this._rulesBySelector[selector] = rule;
|
---|
65 | }
|
---|
66 |
|
---|
67 | rule.setStyles(styles);
|
---|
68 | return this;
|
---|
69 | }
|
---|
70 | }, {
|
---|
71 | key: "getRulesFor",
|
---|
72 | value: function getRulesFor(el) {
|
---|
73 | var ref, rule, rules, selector;
|
---|
74 | rules = [];
|
---|
75 | ref = this._rulesBySelector;
|
---|
76 |
|
---|
77 | for (selector in ref) {
|
---|
78 | rule = ref[selector];
|
---|
79 |
|
---|
80 | if (rule.selector.matches(el)) {
|
---|
81 | rules.push(rule);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | return rules;
|
---|
86 | }
|
---|
87 | }], [{
|
---|
88 | key: "normalizeSelector",
|
---|
89 | value: function normalizeSelector(selector) {
|
---|
90 | return selector.replace(/[\s]+/g, ' ').replace(/[\s]*([>\,\+]{1})[\s]*/g, '$1').trim();
|
---|
91 | }
|
---|
92 | }, {
|
---|
93 | key: "splitSelectors",
|
---|
94 | value: function splitSelectors(s) {
|
---|
95 | return s.trim().split(',');
|
---|
96 | }
|
---|
97 | }]);
|
---|
98 |
|
---|
99 | return StyleSheet;
|
---|
100 | }();
|
---|
101 |
|
---|
102 | ;
|
---|
103 | self = StyleSheet;
|
---|
104 | return StyleSheet;
|
---|
105 | }.call(void 0); |
---|