MixedDeclarationSet.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Generated by CoffeeScript 1.9.3
  2. var MixedDeclarationSet,
  3. slice = [].slice;
  4. module.exports = MixedDeclarationSet = (function() {
  5. var self;
  6. self = MixedDeclarationSet;
  7. MixedDeclarationSet.mix = function() {
  8. var i, len, mixed, ruleSets, rules;
  9. ruleSets = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  10. mixed = new self;
  11. for (i = 0, len = ruleSets.length; i < len; i++) {
  12. rules = ruleSets[i];
  13. mixed.mixWithList(rules);
  14. }
  15. return mixed;
  16. };
  17. function MixedDeclarationSet() {
  18. this._declarations = {};
  19. }
  20. MixedDeclarationSet.prototype.mixWithList = function(rules) {
  21. var i, len, rule;
  22. rules.sort(function(a, b) {
  23. return a.selector.priority > b.selector.priority;
  24. });
  25. for (i = 0, len = rules.length; i < len; i++) {
  26. rule = rules[i];
  27. this._mixWithRule(rule);
  28. }
  29. return this;
  30. };
  31. MixedDeclarationSet.prototype._mixWithRule = function(rule) {
  32. var dec, prop, ref;
  33. ref = rule.styles._declarations;
  34. for (prop in ref) {
  35. dec = ref[prop];
  36. this._mixWithDeclaration(dec);
  37. }
  38. };
  39. MixedDeclarationSet.prototype._mixWithDeclaration = function(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. MixedDeclarationSet.prototype.get = function(prop) {
  48. if (prop == null) {
  49. return this._declarations;
  50. }
  51. if (this._declarations[prop] == null) {
  52. return null;
  53. }
  54. return this._declarations[prop].val;
  55. };
  56. MixedDeclarationSet.prototype.toObject = function() {
  57. var dec, obj, prop, ref;
  58. obj = {};
  59. ref = this._declarations;
  60. for (prop in ref) {
  61. dec = ref[prop];
  62. obj[prop] = dec.val;
  63. }
  64. return obj;
  65. };
  66. return MixedDeclarationSet;
  67. })();