web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

  1. // Generated by CoffeeScript 1.9.3
  2. var MixedDeclarationSet, StyleSheet, Styles, terminalWidth;
  3. StyleSheet = require('./styles/StyleSheet');
  4. MixedDeclarationSet = require('./styles/rule/MixedDeclarationSet');
  5. terminalWidth = require('../tools').getCols();
  6. module.exports = Styles = (function() {
  7. var self;
  8. self = Styles;
  9. Styles.defaultRules = {
  10. '*': {
  11. display: 'inline'
  12. },
  13. 'body': {
  14. background: 'none',
  15. color: 'white',
  16. display: 'block',
  17. width: terminalWidth + ' !important'
  18. }
  19. };
  20. function Styles() {
  21. this._defaultStyles = new StyleSheet;
  22. this._userStyles = new StyleSheet;
  23. this._setDefaultStyles();
  24. }
  25. Styles.prototype._setDefaultStyles = function() {
  26. this._defaultStyles.setRule(self.defaultRules);
  27. };
  28. Styles.prototype.setRule = function(selector, rules) {
  29. this._userStyles.setRule.apply(this._userStyles, arguments);
  30. return this;
  31. };
  32. Styles.prototype.getStyleFor = function(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. Styles.prototype._getRawStyleFor = function(el) {
  41. var def, user;
  42. def = this._defaultStyles.getRulesFor(el);
  43. user = this._userStyles.getRulesFor(el);
  44. return MixedDeclarationSet.mix(def, user).toObject();
  45. };
  46. Styles.prototype._getComputedStyleFor = function(el) {
  47. var decs, parent, prop, ref, val;
  48. decs = {};
  49. parent = el.parent;
  50. ref = this._getRawStyleFor(el);
  51. for (prop in ref) {
  52. val = ref[prop];
  53. if (val !== 'inherit') {
  54. decs[prop] = val;
  55. } else {
  56. throw Error("Inherited styles are not supported yet.");
  57. }
  58. }
  59. return decs;
  60. };
  61. return Styles;
  62. })();