CSSHostRule.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //.CommonJS
  2. var CSSOM = {
  3. CSSRule: require("./CSSRule").CSSRule,
  4. CSSRuleList: require("./CSSRuleList").CSSRuleList
  5. };
  6. ///CommonJS
  7. /**
  8. * @constructor
  9. * @see http://www.w3.org/TR/shadow-dom/#host-at-rule
  10. * @see http://html5index.org/Shadow%20DOM%20-%20CSSHostRule.html
  11. * @deprecated This rule was part of early Shadow DOM drafts but was removed in favor of the more flexible :host and :host-context() pseudo-classes in modern CSS for Web Components.
  12. */
  13. CSSOM.CSSHostRule = function CSSHostRule() {
  14. CSSOM.CSSRule.call(this);
  15. this.cssRules = new CSSOM.CSSRuleList();
  16. };
  17. CSSOM.CSSHostRule.prototype = Object.create(CSSOM.CSSRule.prototype);
  18. CSSOM.CSSHostRule.prototype.constructor = CSSOM.CSSHostRule;
  19. Object.setPrototypeOf(CSSOM.CSSHostRule, CSSOM.CSSRule);
  20. Object.defineProperty(CSSOM.CSSHostRule.prototype, "type", {
  21. value: 1001,
  22. writable: false
  23. });
  24. //FIXME
  25. //CSSOM.CSSHostRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
  26. //CSSOM.CSSHostRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
  27. Object.defineProperty(CSSOM.CSSHostRule.prototype, "cssText", {
  28. get: function() {
  29. var values = "";
  30. var valuesArr = [" {"];
  31. if (this.cssRules.length) {
  32. valuesArr.push(this.cssRules.reduce(function(acc, rule){
  33. if (rule.cssText !== "") {
  34. acc.push(rule.cssText);
  35. }
  36. return acc;
  37. }, []).join("\n "));
  38. }
  39. values = valuesArr.join("\n ") + "\n}";
  40. return "@host" + values;
  41. }
  42. });
  43. //.CommonJS
  44. exports.CSSHostRule = CSSOM.CSSHostRule;
  45. ///CommonJS