Styles.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, StyleSheet, Styles, terminalWidth;
  7. StyleSheet = require('./styles/StyleSheet');
  8. MixedDeclarationSet = require('./styles/rule/MixedDeclarationSet');
  9. terminalWidth = require('../tools').getCols();
  10. module.exports = Styles = function () {
  11. var self;
  12. var Styles = /*#__PURE__*/function () {
  13. function Styles() {
  14. _classCallCheck(this, Styles);
  15. this._defaultStyles = new StyleSheet();
  16. this._userStyles = new StyleSheet();
  17. this._setDefaultStyles();
  18. }
  19. _createClass(Styles, [{
  20. key: "_setDefaultStyles",
  21. value: function _setDefaultStyles() {
  22. this._defaultStyles.setRule(self.defaultRules);
  23. }
  24. }, {
  25. key: "setRule",
  26. value: function setRule(selector, rules) {
  27. this._userStyles.setRule.apply(this._userStyles, arguments);
  28. return this;
  29. }
  30. }, {
  31. key: "getStyleFor",
  32. value: function getStyleFor(el) {
  33. var styles;
  34. styles = el.styles;
  35. if (styles == null) {
  36. el.styles = styles = this._getComputedStyleFor(el);
  37. }
  38. return styles;
  39. }
  40. }, {
  41. key: "_getRawStyleFor",
  42. value: function _getRawStyleFor(el) {
  43. var def, user;
  44. def = this._defaultStyles.getRulesFor(el);
  45. user = this._userStyles.getRulesFor(el);
  46. return MixedDeclarationSet.mix(def, user).toObject();
  47. }
  48. }, {
  49. key: "_getComputedStyleFor",
  50. value: function _getComputedStyleFor(el) {
  51. var decs, parent, prop, ref, val;
  52. decs = {};
  53. parent = el.parent;
  54. ref = this._getRawStyleFor(el);
  55. for (prop in ref) {
  56. val = ref[prop];
  57. if (val !== 'inherit') {
  58. decs[prop] = val;
  59. } else {
  60. throw Error("Inherited styles are not supported yet.");
  61. }
  62. }
  63. return decs;
  64. }
  65. }]);
  66. return Styles;
  67. }();
  68. ;
  69. self = Styles;
  70. Styles.defaultRules = {
  71. '*': {
  72. display: 'inline'
  73. },
  74. 'body': {
  75. background: 'none',
  76. color: 'white',
  77. display: 'block',
  78. width: terminalWidth + ' !important'
  79. }
  80. };
  81. return Styles;
  82. }.call(void 0);