aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/@acemir/cssom/lib/CSSCounterStyleRule.js
blob: 44c43300034a0427355ae7bb0fac2c7f82aac84f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//.CommonJS
var CSSOM = {
	CSSRule: require("./CSSRule").CSSRule
};
///CommonJS


/**
 * @constructor
 * @see https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface
 */
CSSOM.CSSCounterStyleRule = function CSSCounterStyleRule() {
	CSSOM.CSSRule.call(this);
    this.name = "";
	this.__props = "";
};

CSSOM.CSSCounterStyleRule.prototype = Object.create(CSSOM.CSSRule.prototype);
CSSOM.CSSCounterStyleRule.prototype.constructor = CSSOM.CSSCounterStyleRule;

Object.setPrototypeOf(CSSOM.CSSCounterStyleRule, CSSOM.CSSRule);

Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "type", {
	value: 11,
	writable: false
});

Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "cssText", {
	get: function() {
		// FIXME : Implement real cssText generation based on properties
		return "@counter-style " + this.name + " { " + this.__props + " }";
	}
});

/**
 * NON-STANDARD
 * Rule text parser.
 * @param {string} cssText
 */
Object.defineProperty(CSSOM.CSSCounterStyleRule.prototype, "parse", {
	value: function(cssText) {
		// Extract the name from "@counter-style <name> { ... }"
		var match = cssText.match(/@counter-style\s+([^\s{]+)\s*\{([^]*)\}/);
		if (match) {
			this.name = match[1];
			// Get the text inside the brackets and clean it up
			var propsText = match[2];
			this.__props = propsText.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function (match, quote) {
				return quote ? match : ' ';
			});
		}
	}
});

//.CommonJS
exports.CSSCounterStyleRule = CSSOM.CSSCounterStyleRule;
///CommonJS