90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
|
|
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
var _RuleList = require('../RuleList');
|
|
|
|
var _RuleList2 = _interopRequireDefault(_RuleList);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
/**
|
|
* Conditional rule for @media, @supports
|
|
*/
|
|
var ConditionalRule = function () {
|
|
function ConditionalRule(key, styles, options) {
|
|
_classCallCheck(this, ConditionalRule);
|
|
|
|
this.type = 'conditional';
|
|
this.isProcessed = false;
|
|
|
|
this.key = key;
|
|
this.options = options;
|
|
this.rules = new _RuleList2['default'](_extends({}, options, { parent: this }));
|
|
|
|
for (var name in styles) {
|
|
this.rules.add(name, styles[name]);
|
|
}
|
|
|
|
this.rules.process();
|
|
}
|
|
|
|
/**
|
|
* Get a rule.
|
|
*/
|
|
|
|
|
|
_createClass(ConditionalRule, [{
|
|
key: 'getRule',
|
|
value: function getRule(name) {
|
|
return this.rules.get(name);
|
|
}
|
|
|
|
/**
|
|
* Get index of a rule.
|
|
*/
|
|
|
|
}, {
|
|
key: 'indexOf',
|
|
value: function indexOf(rule) {
|
|
return this.rules.indexOf(rule);
|
|
}
|
|
|
|
/**
|
|
* Create and register rule, run plugins.
|
|
*/
|
|
|
|
}, {
|
|
key: 'addRule',
|
|
value: function addRule(name, style, options) {
|
|
var rule = this.rules.add(name, style, options);
|
|
this.options.jss.plugins.onProcessRule(rule);
|
|
return rule;
|
|
}
|
|
|
|
/**
|
|
* Generates a CSS string.
|
|
*/
|
|
|
|
}, {
|
|
key: 'toString',
|
|
value: function toString() {
|
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { indent: 1 };
|
|
|
|
var inner = this.rules.toString(options);
|
|
return inner ? this.key + ' {\n' + inner + '\n}' : '';
|
|
}
|
|
}]);
|
|
|
|
return ConditionalRule;
|
|
}();
|
|
|
|
exports['default'] = ConditionalRule; |