CSSCounterStyleRule.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //.CommonJS
  2. var CSSOM = {
  3. CSSRule: require("./CSSRule").CSSRule
  4. };
  5. ///CommonJS
  6. /**
  7. * @constructor
  8. * @see https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface
  9. */
  10. CSSOM.CSSCounterStyleRule = function CSSCounterStyleRule() {
  11. CSSOM.CSSRule.call(this);
  12. this.name = "";
  13. this.__props = "";
  14. };
  15. CSSOM.CSSCounterStyleRule.prototype = Object.create(CSSOM.CSSRule.prototype);
  16. CSSOM.CSSCounterStyleRule.prototype.constructor = CSSOM.CSSCounterStyleRule;
  17. Object.setPrototypeOf(CSSOM.CSSCounterStyleRule, CSSOM.CSSRule);
  18. Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "type", {
  19. value: 11,
  20. writable: false
  21. });
  22. Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "cssText", {
  23. get: function() {
  24. // FIXME : Implement real cssText generation based on properties
  25. return "@counter-style " + this.name + " { " + this.__props + " }";
  26. }
  27. });
  28. /**
  29. * NON-STANDARD
  30. * Rule text parser.
  31. * @param {string} cssText
  32. */
  33. Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "parse", {
  34. value: function(cssText) {
  35. // Extract the name from "@counter-style <name> { ... }"
  36. var match = cssText.match(/@counter-style\s+([^\s{]+)\s*\{([^]*)\}/);
  37. if (match) {
  38. this.name = match[1];
  39. // Get the text inside the brackets and clean it up
  40. var propsText = match[2];
  41. this.__props = propsText.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function (match, quote) {
  42. return quote ? match : ' ';
  43. });
  44. }
  45. }
  46. });
  47. //.CommonJS
  48. exports.CSSCounterStyleRule = CSSOM.CSSCounterStyleRule;
  49. ///CommonJS