@acemir/cssom 0.9.19 → 0.9.21

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.
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule
5
6
  };
6
7
  ///CommonJS
@@ -12,13 +13,17 @@ var CSSOM = {
12
13
  */
13
14
  CSSOM.CSSConditionRule = function CSSConditionRule() {
14
15
  CSSOM.CSSGroupingRule.call(this);
15
- this.cssRules = [];
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;
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule,
5
6
  CSSConditionRule: require("./CSSConditionRule").CSSConditionRule,
6
7
  };
@@ -21,27 +22,35 @@ CSSOM.CSSContainerRule.prototype.constructor = CSSOM.CSSContainerRule;
21
22
  CSSOM.CSSContainerRule.prototype.type = 17;
22
23
 
23
24
  Object.defineProperties(CSSOM.CSSContainerRule.prototype, {
24
- "conditionText": {
25
- get: function() {
26
- return this.containerText;
27
- },
28
- set: function(value) {
29
- this.containerText = value;
30
- },
31
- configurable: true,
32
- enumerable: true
33
- },
34
25
  "cssText": {
35
26
  get: function() {
36
27
  var cssTexts = [];
37
28
  for (var i=0, length=this.cssRules.length; i < length; i++) {
38
29
  cssTexts.push(this.cssRules[i].cssText);
39
30
  }
40
- return "@container " + this.containerText + " {" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
31
+ return "@container " + this.conditionText + " {" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
41
32
  },
42
33
  configurable: true,
43
34
  enumerable: true
44
- }
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
+ },
45
54
  });
46
55
 
47
56
 
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  MatcherList: require("./MatcherList").MatcherList
5
6
  };
6
7
  ///CommonJS
@@ -13,7 +14,7 @@ var CSSOM = {
13
14
  CSSOM.CSSDocumentRule = function CSSDocumentRule() {
14
15
  CSSOM.CSSRule.call(this);
15
16
  this.matcher = new CSSOM.MatcherList();
16
- this.cssRules = [];
17
+ this.cssRules = new CSSOM.CSSRuleList();
17
18
  };
18
19
 
19
20
  CSSOM.CSSDocumentRule.prototype = new CSSOM.CSSRule();
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  parse: require('./parse').parse
5
6
  };
6
7
  var errorUtils = require("./errorUtils").errorUtils;
@@ -13,7 +14,7 @@ var errorUtils = require("./errorUtils").errorUtils;
13
14
  */
14
15
  CSSOM.CSSGroupingRule = function CSSGroupingRule() {
15
16
  CSSOM.CSSRule.call(this);
16
- this.cssRules = [];
17
+ this.cssRules = new CSSOM.CSSRuleList();
17
18
  };
18
19
 
19
20
  CSSOM.CSSGroupingRule.prototype = new CSSOM.CSSRule();
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
- CSSRule: require("./CSSRule").CSSRule
3
+ CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList
4
5
  };
5
6
  ///CommonJS
6
7
 
@@ -11,7 +12,7 @@ var CSSOM = {
11
12
  */
12
13
  CSSOM.CSSHostRule = function CSSHostRule() {
13
14
  CSSOM.CSSRule.call(this);
14
- this.cssRules = [];
15
+ this.cssRules = new CSSOM.CSSRuleList();
15
16
  };
16
17
 
17
18
  CSSOM.CSSHostRule.prototype = new CSSOM.CSSRule();
@@ -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;
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  parse: require("./parse").parse
5
6
  };
6
7
  var errorUtils = require("./errorUtils").errorUtils;
@@ -14,7 +15,7 @@ var errorUtils = require("./errorUtils").errorUtils;
14
15
  CSSOM.CSSKeyframesRule = function CSSKeyframesRule() {
15
16
  CSSOM.CSSRule.call(this);
16
17
  this.name = '';
17
- this.cssRules = [];
18
+ this.cssRules = new CSSOM.CSSRuleList();
18
19
 
19
20
  // Set up initial indexed access
20
21
  this._setupIndexedAccess();
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule,
5
6
  };
6
7
  ///CommonJS
@@ -12,7 +13,6 @@ var CSSOM = {
12
13
  CSSOM.CSSLayerBlockRule = function CSSLayerBlockRule() {
13
14
  CSSOM.CSSGroupingRule.call(this);
14
15
  this.name = "";
15
- this.cssRules = [];
16
16
  };
17
17
 
18
18
  CSSOM.CSSLayerBlockRule.prototype = new CSSOM.CSSGroupingRule();
@@ -1,6 +1,7 @@
1
1
  //.CommonJS
2
2
  var CSSOM = {
3
3
  CSSRule: require("./CSSRule").CSSRule,
4
+ CSSRuleList: require("./CSSRuleList").CSSRuleList,
4
5
  CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule,
5
6
  CSSConditionRule: require("./CSSConditionRule").CSSConditionRule,
6
7
  MediaList: require("./MediaList").MediaList
@@ -15,7 +16,7 @@ var CSSOM = {
15
16
  */
16
17
  CSSOM.CSSMediaRule = function CSSMediaRule() {
17
18
  CSSOM.CSSConditionRule.call(this);
18
- this.media = new CSSOM.MediaList();
19
+ this.__media = new CSSOM.MediaList();
19
20
  };
20
21
 
21
22
  CSSOM.CSSMediaRule.prototype = new CSSOM.CSSConditionRule();
@@ -24,16 +25,24 @@ CSSOM.CSSMediaRule.prototype.type = 4;
24
25
 
25
26
  // https://opensource.apple.com/source/WebCore/WebCore-7611.1.21.161.3/css/CSSMediaRule.cpp
26
27
  Object.defineProperties(CSSOM.CSSMediaRule.prototype, {
27
- "conditionText": {
28
+ "media": {
28
29
  get: function() {
29
- return this.media.mediaText;
30
+ return this.__media;
30
31
  },
31
32
  set: function(value) {
32
- this.media.mediaText = value;
33
+ if (typeof value === "string") {
34
+ this.__media.mediaText = value;
35
+ } else {
36
+ this.__media = value;
37
+ }
33
38
  },
34
- configurable: true,
35
39
  enumerable: true
36
40
  },
41
+ "conditionText": {
42
+ get: function() {
43
+ return this.media.mediaText;
44
+ }
45
+ },
37
46
  "cssText": {
38
47
  get: function() {
39
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;