@acemir/cssom 0.9.20 → 0.9.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,12 +13,17 @@ var CSSOM = {
13
13
  */
14
14
  CSSOM.CSSConditionRule = function CSSConditionRule() {
15
15
  CSSOM.CSSGroupingRule.call(this);
16
+ this.__conditionText = '';
16
17
  };
17
18
 
18
19
  CSSOM.CSSConditionRule.prototype = new CSSOM.CSSGroupingRule();
19
20
  CSSOM.CSSConditionRule.prototype.constructor = CSSOM.CSSConditionRule;
20
- CSSOM.CSSConditionRule.prototype.conditionText = ''
21
- CSSOM.CSSConditionRule.prototype.cssText = ''
21
+
22
+ Object.defineProperty(CSSOM.CSSConditionRule.prototype, "conditionText", {
23
+ get: function () {
24
+ return this.__conditionText;
25
+ }
26
+ });
22
27
 
23
28
  //.CommonJS
24
29
  exports.CSSConditionRule = CSSOM.CSSConditionRule;
@@ -22,27 +22,35 @@ CSSOM.CSSContainerRule.prototype.constructor = CSSOM.CSSContainerRule;
22
22
  CSSOM.CSSContainerRule.prototype.type = 17;
23
23
 
24
24
  Object.defineProperties(CSSOM.CSSContainerRule.prototype, {
25
- "conditionText": {
26
- get: function() {
27
- return this.containerText;
28
- },
29
- set: function(value) {
30
- this.containerText = value;
31
- },
32
- configurable: true,
33
- enumerable: true
34
- },
35
25
  "cssText": {
36
26
  get: function() {
37
27
  var cssTexts = [];
38
28
  for (var i=0, length=this.cssRules.length; i < length; i++) {
39
29
  cssTexts.push(this.cssRules[i].cssText);
40
30
  }
41
- return "@container " + this.containerText + " {" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
31
+ return "@container " + this.conditionText + " {" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
42
32
  },
43
33
  configurable: true,
44
34
  enumerable: true
45
- }
35
+ },
36
+ "containerName": {
37
+ get: function() {
38
+ var parts = this.conditionText.trim().split(/\s+/);
39
+ if (parts.length > 1 && parts[0] !== '(' && !parts[0].startsWith('(')) {
40
+ return parts[0];
41
+ }
42
+ return "";
43
+ }
44
+ },
45
+ "containerQuery": {
46
+ get: function() {
47
+ var parts = this.conditionText.trim().split(/\s+/);
48
+ if (parts.length > 1 && parts[0] !== '(' && !parts[0].startsWith('(')) {
49
+ return parts.slice(1).join(' ');
50
+ }
51
+ return this.conditionText;
52
+ }
53
+ },
46
54
  });
47
55
 
48
56
 
@@ -14,21 +14,25 @@ var CSSOM = {
14
14
  */
15
15
  CSSOM.CSSImportRule = function CSSImportRule() {
16
16
  CSSOM.CSSRule.call(this);
17
- this.href = "";
18
- this.media = new CSSOM.MediaList();
19
- this.layerName = null;
20
- this.supportsText = null;
21
- this.styleSheet = new CSSOM.CSSStyleSheet();
17
+ this.__href = "";
18
+ this.__media = new CSSOM.MediaList();
19
+ this.__layerName = null;
20
+ this.__supportsText = null;
21
+ this.__styleSheet = new CSSOM.CSSStyleSheet();
22
22
  };
23
23
 
24
24
  CSSOM.CSSImportRule.prototype = new CSSOM.CSSRule();
25
25
  CSSOM.CSSImportRule.prototype.constructor = CSSOM.CSSImportRule;
26
- CSSOM.CSSImportRule.prototype.type = 3;
26
+
27
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "type", {
28
+ value: 3,
29
+ writable: false
30
+ });
27
31
 
28
32
  Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
29
33
  get: function() {
30
34
  var mediaText = this.media.mediaText;
31
- return "@import url(\"" + this.href + "\")" + (this.layerName !== null ? " layer" + (this.layerName && "(" + this.layerName + ")") : "" ) + (this.supportsText ? " supports(" + this.supportsText + ")" : "" ) + (mediaText ? " " + mediaText : "") + ";";
35
+ return "@import url(\"" + this.href.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + "\")" + (this.layerName !== null ? " layer" + (this.layerName && "(" + this.layerName + ")") : "" ) + (this.supportsText ? " supports(" + this.supportsText + ")" : "" ) + (mediaText ? " " + mediaText : "") + ";";
32
36
  },
33
37
  set: function(cssText) {
34
38
  var i = 0;
@@ -47,8 +51,40 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
47
51
 
48
52
  var layerRegExp = /layer\(([^)]*)\)/;
49
53
  var layerRuleNameRegExp = /^(-?[_a-zA-Z]+(\.[_a-zA-Z]+)*[_a-zA-Z0-9-]*)$/;
50
- var supportsRegExp = /supports\(([^)]+)\)/;
51
54
  var doubleOrMoreSpacesRegExp = /\s{2,}/g;
55
+
56
+ /**
57
+ * Extracts the content inside supports() handling nested parentheses.
58
+ * @param {string} text - The text to parse
59
+ * @returns {object|null} - {content: string, endIndex: number} or null if not found
60
+ */
61
+ function extractSupportsContent(text) {
62
+ var supportsIndex = text.indexOf('supports(');
63
+ if (supportsIndex !== 0) {
64
+ return null;
65
+ }
66
+
67
+ var depth = 0;
68
+ var start = supportsIndex + 'supports('.length;
69
+ var i = start;
70
+
71
+ for (; i < text.length; i++) {
72
+ if (text[i] === '(') {
73
+ depth++;
74
+ } else if (text[i] === ')') {
75
+ if (depth === 0) {
76
+ // Found the closing parenthesis for supports()
77
+ return {
78
+ content: text.slice(start, i),
79
+ endIndex: i
80
+ };
81
+ }
82
+ depth--;
83
+ }
84
+ }
85
+
86
+ return null; // Unbalanced parentheses
87
+ }
52
88
 
53
89
  for (var character; (character = cssText.charAt(i)); i++) {
54
90
 
@@ -89,7 +125,7 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
89
125
  url = url.slice(1, -1);
90
126
  }
91
127
  }
92
- this.href = url;
128
+ this.__href = url;
93
129
  i = index;
94
130
  state = 'media';
95
131
  }
@@ -101,7 +137,7 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
101
137
  if (!index) {
102
138
  throw i + ": '\"' not found";
103
139
  }
104
- this.href = cssText.slice(i + 1, index);
140
+ this.__href = cssText.slice(i + 1, index);
105
141
  i = index;
106
142
  state = 'media';
107
143
  }
@@ -113,7 +149,7 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
113
149
  if (!index) {
114
150
  throw i + ': "\'" not found';
115
151
  }
116
- this.href = cssText.slice(i + 1, index);
152
+ this.__href = cssText.slice(i + 1, index);
117
153
  i = index;
118
154
  state = 'media';
119
155
  }
@@ -131,7 +167,7 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
131
167
  var layerName = layerMatch[1].trim();
132
168
 
133
169
  if (layerName.match(layerRuleNameRegExp) !== null) {
134
- this.layerName = layerMatch[1].trim();
170
+ this.__layerName = layerMatch[1].trim();
135
171
  bufferTrimmed = bufferTrimmed.replace(layerRegExp, '')
136
172
  .replace(doubleOrMoreSpacesRegExp, ' ') // Replace double or more spaces with single space
137
173
  .trim();
@@ -144,19 +180,19 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
144
180
  }
145
181
  }
146
182
  } else {
147
- this.layerName = "";
183
+ this.__layerName = "";
148
184
  bufferTrimmed = bufferTrimmed.substring('layer'.length).trim()
149
185
  }
150
186
  }
151
187
 
152
- var supportsMatch = bufferTrimmed.match(supportsRegExp);
188
+ var supportsResult = extractSupportsContent(bufferTrimmed);
153
189
 
154
- if (supportsMatch && supportsMatch.index === 0) {
190
+ if (supportsResult) {
155
191
  // REVIEW: In the browser, an empty supports() invalidates and ignores the entire @import rule
156
- this.supportsText = supportsMatch[1].trim();
157
- bufferTrimmed = bufferTrimmed.replace(supportsRegExp, '')
158
- .replace(doubleOrMoreSpacesRegExp, ' ') // Replace double or more spaces with single space
159
- .trim();
192
+ this.__supportsText = supportsResult.content.trim();
193
+ // Remove the entire supports(...) from the buffer
194
+ bufferTrimmed = bufferTrimmed.slice(0, 0) + bufferTrimmed.slice(supportsResult.endIndex + 1);
195
+ bufferTrimmed = bufferTrimmed.replace(doubleOrMoreSpacesRegExp, ' ').trim();
160
196
  }
161
197
 
162
198
  // REVIEW: In the browser, any invalid media is replaced with 'not all'
@@ -177,6 +213,43 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
177
213
  }
178
214
  });
179
215
 
216
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "href", {
217
+ get: function() {
218
+ return this.__href;
219
+ }
220
+ });
221
+
222
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "media", {
223
+ get: function() {
224
+ return this.__media;
225
+ },
226
+ set: function(value) {
227
+ if (typeof value === "string") {
228
+ this.__media.mediaText = value;
229
+ } else {
230
+ this.__media = value;
231
+ }
232
+ }
233
+ });
234
+
235
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "layerName", {
236
+ get: function() {
237
+ return this.__layerName;
238
+ }
239
+ });
240
+
241
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "supportsText", {
242
+ get: function() {
243
+ return this.__supportsText;
244
+ }
245
+ });
246
+
247
+ Object.defineProperty(CSSOM.CSSImportRule.prototype, "styleSheet", {
248
+ get: function() {
249
+ return this.__styleSheet;
250
+ }
251
+ });
252
+
180
253
 
181
254
  //.CommonJS
182
255
  exports.CSSImportRule = CSSOM.CSSImportRule;
@@ -16,7 +16,7 @@ var CSSOM = {
16
16
  */
17
17
  CSSOM.CSSMediaRule = function CSSMediaRule() {
18
18
  CSSOM.CSSConditionRule.call(this);
19
- this.media = new CSSOM.MediaList();
19
+ this.__media = new CSSOM.MediaList();
20
20
  };
21
21
 
22
22
  CSSOM.CSSMediaRule.prototype = new CSSOM.CSSConditionRule();
@@ -25,16 +25,24 @@ CSSOM.CSSMediaRule.prototype.type = 4;
25
25
 
26
26
  // https://opensource.apple.com/source/WebCore/WebCore-7611.1.21.161.3/css/CSSMediaRule.cpp
27
27
  Object.defineProperties(CSSOM.CSSMediaRule.prototype, {
28
- "conditionText": {
28
+ "media": {
29
29
  get: function() {
30
- return this.media.mediaText;
30
+ return this.__media;
31
31
  },
32
32
  set: function(value) {
33
- this.media.mediaText = value;
33
+ if (typeof value === "string") {
34
+ this.__media.mediaText = value;
35
+ } else {
36
+ this.__media = value;
37
+ }
34
38
  },
35
- configurable: true,
36
39
  enumerable: true
37
40
  },
41
+ "conditionText": {
42
+ get: function() {
43
+ return this.media.mediaText;
44
+ }
45
+ },
38
46
  "cssText": {
39
47
  get: function() {
40
48
  var cssTexts = [];
@@ -12,23 +12,25 @@ var CSSOM = {
12
12
  */
13
13
  CSSOM.CSSNamespaceRule = function CSSNamespaceRule() {
14
14
  CSSOM.CSSRule.call(this);
15
- this.prefix = "";
16
- this.namespaceURI = "";
17
- this.styleSheet = new CSSOM.CSSStyleSheet();
15
+ this.__prefix = "";
16
+ this.__namespaceURI = "";
18
17
  };
19
18
 
20
19
  CSSOM.CSSNamespaceRule.prototype = new CSSOM.CSSRule();
21
20
  CSSOM.CSSNamespaceRule.prototype.constructor = CSSOM.CSSNamespaceRule;
22
- CSSOM.CSSNamespaceRule.prototype.type = 10;
21
+
22
+ Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "type", {
23
+ value: 10,
24
+ writable: false
25
+ });
23
26
 
24
27
  Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "cssText", {
25
28
  get: function() {
26
29
  return "@namespace" + (this.prefix && " " + this.prefix) + " url(\"" + this.namespaceURI + "\");";
27
30
  },
28
31
  set: function(cssText) {
29
- // Reset prefix and namespaceURI
30
- this.prefix = "";
31
- this.namespaceURI = "";
32
+ var newPrefix = "";
33
+ var newNamespaceURI = "";
32
34
 
33
35
  // Remove @namespace and trim
34
36
  var text = cssText.trim();
@@ -51,26 +53,40 @@ Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "cssText", {
51
53
  if (match) {
52
54
  // If prefix is present
53
55
  if (match[1]) {
54
- this.prefix = match[1];
56
+ newPrefix = match[1];
55
57
  }
56
58
  // If url(...) form with quotes
57
59
  if (typeof match[3] !== "undefined") {
58
- this.namespaceURI = match[3];
60
+ newNamespaceURI = match[3];
59
61
  }
60
62
  // If url(...) form without quotes
61
63
  else if (typeof match[4] !== "undefined") {
62
- this.namespaceURI = match[4].trim();
64
+ newNamespaceURI = match[4].trim();
63
65
  }
64
66
  // If quoted string form
65
67
  else if (typeof match[6] !== "undefined") {
66
- this.namespaceURI = match[6];
68
+ newNamespaceURI = match[6];
67
69
  }
70
+
71
+ this.__prefix = newPrefix;
72
+ this.__namespaceURI = newNamespaceURI;
68
73
  } else {
69
74
  throw new DOMException("Invalid @namespace rule", "InvalidStateError");
70
75
  }
71
76
  }
72
77
  });
73
78
 
79
+ Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "prefix", {
80
+ get: function() {
81
+ return this.__prefix;
82
+ }
83
+ });
84
+
85
+ Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "namespaceURI", {
86
+ get: function() {
87
+ return this.__namespaceURI;
88
+ }
89
+ });
74
90
 
75
91
  //.CommonJS
76
92
  exports.CSSNamespaceRule = CSSOM.CSSNamespaceRule;
@@ -0,0 +1,275 @@
1
+ //.CommonJS
2
+ var CSSOM = {
3
+ CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
4
+ CSSRule: require("./CSSRule").CSSRule,
5
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
6
+ CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule,
7
+ };
8
+ // Use cssstyle if available
9
+ try {
10
+ CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
11
+ } catch (e) {
12
+ // ignore
13
+ }
14
+ ///CommonJS
15
+
16
+
17
+ /**
18
+ * @constructor
19
+ * @see https://drafts.csswg.org/cssom/#the-csspagerule-interface
20
+ */
21
+ CSSOM.CSSPageRule = function CSSPageRule() {
22
+ CSSOM.CSSGroupingRule.call(this);
23
+ this.__style = new CSSOM.CSSStyleDeclaration();
24
+ this.__style.parentRule = this;
25
+ };
26
+
27
+ CSSOM.CSSPageRule.prototype = new CSSOM.CSSGroupingRule();
28
+ CSSOM.CSSPageRule.prototype.constructor = CSSOM.CSSPageRule;
29
+
30
+ Object.defineProperty(CSSOM.CSSPageRule.prototype, "type", {
31
+ value: 6,
32
+ writable: false
33
+ });
34
+
35
+ Object.defineProperty(CSSOM.CSSPageRule.prototype, "selectorText", {
36
+ get: function() {
37
+ return this.__selectorText;
38
+ },
39
+ set: function(value) {
40
+ if (typeof value === "string") {
41
+ var trimmedValue = value.trim();
42
+
43
+ // Empty selector is valid for @page
44
+ if (trimmedValue === '') {
45
+ this.__selectorText = '';
46
+ return;
47
+ }
48
+
49
+ // Parse @page selectorText for page name and pseudo-pages
50
+ // Valid formats:
51
+ // - (empty - no name, no pseudo-page)
52
+ // - :left, :right, :first, :blank (pseudo-page only)
53
+ // - named (named page only)
54
+ // - named:first (named page with single pseudo-page)
55
+ // - named:first:left (named page with multiple pseudo-pages)
56
+ var atPageRuleSelectorRegExp = /^([^\s:]+)?((?::\w+)*)$/;
57
+ var match = trimmedValue.match(atPageRuleSelectorRegExp);
58
+ if (match) {
59
+ var pageName = match[1] || '';
60
+ var pseudoPages = match[2] || '';
61
+
62
+ // Validate page name if present
63
+ if (pageName) {
64
+ var cssCustomIdentifierRegExp = /^(-?[_a-zA-Z]+(\.[_a-zA-Z]+)*[_a-zA-Z0-9-]*)$/; // Validates a css custom identifier
65
+ // Page name can be an identifier or a string
66
+ if (!cssCustomIdentifierRegExp.test(pageName)) {
67
+ return;
68
+ }
69
+ }
70
+
71
+ // Validate pseudo-pages if present
72
+ if (pseudoPages) {
73
+ var pseudos = pseudoPages.split(':').filter(function(p) { return p; });
74
+ var validPseudos = ['left', 'right', 'first', 'blank'];
75
+ var allValid = true;
76
+ for (var j = 0; j < pseudos.length; j++) {
77
+ if (validPseudos.indexOf(pseudos[j].toLowerCase()) === -1) {
78
+ allValid = false;
79
+ break;
80
+ }
81
+ }
82
+
83
+ if (!allValid) {
84
+ return; // Invalid pseudo-page, do nothing
85
+ }
86
+ }
87
+
88
+ this.__selectorText = pageName + pseudoPages.toLowerCase();
89
+ }
90
+ }
91
+ }
92
+ });
93
+
94
+ Object.defineProperty(CSSOM.CSSPageRule.prototype, "style", {
95
+ get: function() {
96
+ return this.__style;
97
+ },
98
+ set: function(value) {
99
+ if (typeof value === "string") {
100
+ this.__style.cssText = value;
101
+ } else {
102
+ this.__style = value;
103
+ }
104
+ }
105
+ });
106
+
107
+ Object.defineProperty(CSSOM.CSSPageRule.prototype, "cssText", {
108
+ get: function() {
109
+ var values = ""
110
+ if (this.cssRules.length) {
111
+ var valuesArr = [" {"];
112
+ this.style.cssText && valuesArr.push(this.style.cssText);
113
+ valuesArr.push(this.cssRules.map(function(rule){ return rule.cssText }).join("\n "));
114
+ values = valuesArr.join("\n ") + "\n}"
115
+ } else {
116
+ values = " {" + (this.style.cssText ? " " + this.style.cssText : "") + " }";
117
+ }
118
+ return "@page" + (this.selectorText ? " " + this.selectorText : "") + values;
119
+ },
120
+ set: function(cssText) {
121
+ if (typeof value === "string") {
122
+ var rule = CSSOM.CSSPageRule.parse(cssText);
123
+ this.__style = rule.style;
124
+ this.selectorText = rule.selectorText;
125
+ }
126
+ }
127
+ });
128
+
129
+ /**
130
+ * NON-STANDARD
131
+ * lightweight version of parse.js.
132
+ * @param {string} ruleText
133
+ * @return CSSPageRule
134
+ */
135
+ CSSOM.CSSPageRule.parse = function(ruleText) {
136
+ var i = 0;
137
+ var state = "selector";
138
+ var index;
139
+ var j = i;
140
+ var buffer = "";
141
+
142
+ var SIGNIFICANT_WHITESPACE = {
143
+ "selector": true,
144
+ "value": true
145
+ };
146
+
147
+ var pageRule = new CSSOM.CSSPageRule();
148
+ var name, priority="";
149
+
150
+ for (var character; (character = ruleText.charAt(i)); i++) {
151
+
152
+ switch (character) {
153
+
154
+ case " ":
155
+ case "\t":
156
+ case "\r":
157
+ case "\n":
158
+ case "\f":
159
+ if (SIGNIFICANT_WHITESPACE[state]) {
160
+ // Squash 2 or more white-spaces in the row into 1
161
+ switch (ruleText.charAt(i - 1)) {
162
+ case " ":
163
+ case "\t":
164
+ case "\r":
165
+ case "\n":
166
+ case "\f":
167
+ break;
168
+ default:
169
+ buffer += " ";
170
+ break;
171
+ }
172
+ }
173
+ break;
174
+
175
+ // String
176
+ case '"':
177
+ j = i + 1;
178
+ index = ruleText.indexOf('"', j) + 1;
179
+ if (!index) {
180
+ throw '" is missing';
181
+ }
182
+ buffer += ruleText.slice(i, index);
183
+ i = index - 1;
184
+ break;
185
+
186
+ case "'":
187
+ j = i + 1;
188
+ index = ruleText.indexOf("'", j) + 1;
189
+ if (!index) {
190
+ throw "' is missing";
191
+ }
192
+ buffer += ruleText.slice(i, index);
193
+ i = index - 1;
194
+ break;
195
+
196
+ // Comment
197
+ case "/":
198
+ if (ruleText.charAt(i + 1) === "*") {
199
+ i += 2;
200
+ index = ruleText.indexOf("*/", i);
201
+ if (index === -1) {
202
+ throw new SyntaxError("Missing */");
203
+ } else {
204
+ i = index + 1;
205
+ }
206
+ } else {
207
+ buffer += character;
208
+ }
209
+ break;
210
+
211
+ case "{":
212
+ if (state === "selector") {
213
+ pageRule.selectorText = buffer.trim();
214
+ buffer = "";
215
+ state = "name";
216
+ }
217
+ break;
218
+
219
+ case ":":
220
+ if (state === "name") {
221
+ name = buffer.trim();
222
+ buffer = "";
223
+ state = "value";
224
+ } else {
225
+ buffer += character;
226
+ }
227
+ break;
228
+
229
+ case "!":
230
+ if (state === "value" && ruleText.indexOf("!important", i) === i) {
231
+ priority = "important";
232
+ i += "important".length;
233
+ } else {
234
+ buffer += character;
235
+ }
236
+ break;
237
+
238
+ case ";":
239
+ if (state === "value") {
240
+ pageRule.style.setProperty(name, buffer.trim(), priority);
241
+ priority = "";
242
+ buffer = "";
243
+ state = "name";
244
+ } else {
245
+ buffer += character;
246
+ }
247
+ break;
248
+
249
+ case "}":
250
+ if (state === "value") {
251
+ pageRule.style.setProperty(name, buffer.trim(), priority);
252
+ priority = "";
253
+ buffer = "";
254
+ } else if (state === "name") {
255
+ break;
256
+ } else {
257
+ buffer += character;
258
+ }
259
+ state = "selector";
260
+ break;
261
+
262
+ default:
263
+ buffer += character;
264
+ break;
265
+
266
+ }
267
+ }
268
+
269
+ return pageRule;
270
+
271
+ };
272
+
273
+ //.CommonJS
274
+ exports.CSSPageRule = CSSOM.CSSPageRule;
275
+ ///CommonJS
package/lib/CSSRule.js CHANGED
@@ -37,6 +37,12 @@ Object.defineProperties(CSSOM.CSSRule.prototype, {
37
37
 
38
38
  constructor: { value: CSSOM.CSSRule },
39
39
 
40
+ cssRule: {
41
+ value: "",
42
+ configurable: true,
43
+ enumerable: true
44
+ },
45
+
40
46
  parentRule: {
41
47
  get: function() {
42
48
  return this.__parentRule
@@ -39,7 +39,20 @@ Object.defineProperty(CSSOM.CSSStyleRule.prototype, "selectorText", {
39
39
  return this.__selectorText;
40
40
  },
41
41
  set: function(value) {
42
- this.__selectorText = value;
42
+ if (typeof value === "string") {
43
+ var trimmedValue = value.trim();
44
+
45
+ if (trimmedValue === '') {
46
+ return;
47
+ }
48
+
49
+ // TODO: Setting invalid selectorText should be ignored
50
+ // There are some validations already on lib/parse.js
51
+ // but the same validations should be applied here.
52
+ // Check if we can move these validation logic to a shared function.
53
+
54
+ this.__selectorText = trimmedValue;
55
+ }
43
56
  }
44
57
  });
45
58
 
@@ -76,9 +89,11 @@ Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
76
89
  return text;
77
90
  },
78
91
  set: function(cssText) {
79
- var rule = CSSOM.CSSStyleRule.parse(cssText);
80
- this.__style = rule.style;
81
- this.__selectorText = rule.selectorText;
92
+ if (typeof cssText === "string") {
93
+ var rule = CSSOM.CSSStyleRule.parse(cssText);
94
+ this.__style = rule.style;
95
+ this.selectorText = rule.selectorText;
96
+ }
82
97
  }
83
98
  });
84
99