MixedDeclarationSet.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 MixedDeclarationSet;
  7. module.exports = MixedDeclarationSet = function () {
  8. var self;
  9. var MixedDeclarationSet = /*#__PURE__*/function () {
  10. function MixedDeclarationSet() {
  11. _classCallCheck(this, MixedDeclarationSet);
  12. this._declarations = {};
  13. }
  14. _createClass(MixedDeclarationSet, [{
  15. key: "mixWithList",
  16. value: function mixWithList(rules) {
  17. var i, len, rule;
  18. rules.sort(function (a, b) {
  19. return a.selector.priority > b.selector.priority;
  20. });
  21. for (i = 0, len = rules.length; i < len; i++) {
  22. rule = rules[i];
  23. this._mixWithRule(rule);
  24. }
  25. return this;
  26. }
  27. }, {
  28. key: "_mixWithRule",
  29. value: function _mixWithRule(rule) {
  30. var dec, prop, ref;
  31. ref = rule.styles._declarations;
  32. for (prop in ref) {
  33. dec = ref[prop];
  34. this._mixWithDeclaration(dec);
  35. }
  36. }
  37. }, {
  38. key: "_mixWithDeclaration",
  39. value: function _mixWithDeclaration(dec) {
  40. var cur;
  41. cur = this._declarations[dec.prop];
  42. if (cur != null && cur.important && !dec.important) {
  43. return;
  44. }
  45. this._declarations[dec.prop] = dec;
  46. }
  47. }, {
  48. key: "get",
  49. value: function get(prop) {
  50. if (prop == null) {
  51. return this._declarations;
  52. }
  53. if (this._declarations[prop] == null) {
  54. return null;
  55. }
  56. return this._declarations[prop].val;
  57. }
  58. }, {
  59. key: "toObject",
  60. value: function toObject() {
  61. var dec, obj, prop, ref;
  62. obj = {};
  63. ref = this._declarations;
  64. for (prop in ref) {
  65. dec = ref[prop];
  66. obj[prop] = dec.val;
  67. }
  68. return obj;
  69. }
  70. }], [{
  71. key: "mix",
  72. value: function mix() {
  73. var i, len, mixed, rules;
  74. mixed = new self();
  75. for (var _len = arguments.length, ruleSets = new Array(_len), _key = 0; _key < _len; _key++) {
  76. ruleSets[_key] = arguments[_key];
  77. }
  78. for (i = 0, len = ruleSets.length; i < len; i++) {
  79. rules = ruleSets[i];
  80. mixed.mixWithList(rules);
  81. }
  82. return mixed;
  83. }
  84. }]);
  85. return MixedDeclarationSet;
  86. }();
  87. ;
  88. self = MixedDeclarationSet;
  89. return MixedDeclarationSet;
  90. }.call(void 0);