_Declaration.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // Abstract Style Declaration
  7. var _Declaration;
  8. module.exports = _Declaration = function () {
  9. var self;
  10. var _Declaration = /*#__PURE__*/function () {
  11. function _Declaration(prop1, val) {
  12. _classCallCheck(this, _Declaration);
  13. this.prop = prop1;
  14. this.important = false;
  15. this.set(val);
  16. }
  17. _createClass(_Declaration, [{
  18. key: "get",
  19. value: function get() {
  20. return this._get();
  21. }
  22. }, {
  23. key: "_get",
  24. value: function _get() {
  25. return this.val;
  26. }
  27. }, {
  28. key: "_pickImportantClause",
  29. value: function _pickImportantClause(val) {
  30. if (self.importantClauseRx.test(String(val))) {
  31. this.important = true;
  32. return val.replace(self.importantClauseRx, '');
  33. } else {
  34. this.important = false;
  35. return val;
  36. }
  37. }
  38. }, {
  39. key: "set",
  40. value: function set(val) {
  41. val = self.sanitizeValue(val);
  42. val = this._pickImportantClause(val);
  43. val = val.trim();
  44. if (this._handleNullOrInherit(val)) {
  45. return this;
  46. }
  47. this._set(val);
  48. return this;
  49. }
  50. }, {
  51. key: "_set",
  52. value: function _set(val) {
  53. return this.val = val;
  54. }
  55. }, {
  56. key: "_handleNullOrInherit",
  57. value: function _handleNullOrInherit(val) {
  58. if (val === '') {
  59. this.val = '';
  60. return true;
  61. }
  62. if (val === 'inherit') {
  63. if (this.constructor.inheritAllowed) {
  64. this.val = 'inherit';
  65. } else {
  66. throw Error("Inherit is not allowed for `".concat(this.prop, "`"));
  67. }
  68. return true;
  69. } else {
  70. return false;
  71. }
  72. }
  73. }], [{
  74. key: "setOnto",
  75. value: function setOnto(declarations, prop, val) {
  76. var dec;
  77. if (!(dec = declarations[prop])) {
  78. return declarations[prop] = new this(prop, val);
  79. } else {
  80. return dec.set(val);
  81. }
  82. }
  83. }, {
  84. key: "sanitizeValue",
  85. value: function sanitizeValue(val) {
  86. return String(val).trim().replace(/[\s]+/g, ' ');
  87. }
  88. }]);
  89. return _Declaration;
  90. }();
  91. ;
  92. self = _Declaration;
  93. _Declaration.importantClauseRx = /(\s\!important)$/;
  94. _Declaration.inheritAllowed = false;
  95. return _Declaration;
  96. }.call(void 0);